<?php
class Controller_Storage_Sales extends Controller_Abstract
{
	function actionList()
	{
		$this->_view['title'] = '销售单列表';
		$this->_view['shop'] = Shop::getActiveShop();
		$this->_view['shipping_method'] = Shipping_Method::getShippingMethodByWarehouse('GZ');
		$url_arr = Helper_BSS_Normal::buildCondition();
		if (isset($_GET['is_search']))
		{
			$cp = isset($_GET['cp']) ? $_GET['cp'] : 1;
			$ps = isset($_GET['ps']) ? $_GET['ps'] : 10;
			$url_arr['trash_status'] = Q::ini('custom_flag/sales_order_trash_status/normal/value');
			$url_arr['warehouse_id'] = Warehouse::getDefaultWarehouseId();
			$result = Sales_Order::search($url_arr, $cp, $ps);
			if ($result['ack'] == SUCCESS)
			{
				$sales_order = $result['data'];
				$page = new Helper_BSS_Page($result['pagination'], url('Storage::Sales/List', $url_arr));
				$this->_view['page'] = $page->getPage();
				Sales_Order_Notes::getOrderNotes($sales_order);
				Sales_Order_Item_Attribute::getSalesOrderItemAttr($sales_order);
				$this->_view['sales_order'] = $sales_order;
			}
		}
		$this->_view['url_arr_json'] = json_encode($url_arr);
	}
	
	function actionOperateList()
	{
		$this->_view['title'] = '处理单列表';
		$cp = isset($_GET['cp']) ? $_GET['cp'] : 1;
		$ps = isset($_GET['ps']) ? $_GET['ps'] : 20;
		$shop = Shop::getActiveShop();
		$this->_view['shop'] = $shop;
		$this->_view['shipping_method'] = Shipping_Method::getShippingMethodByWarehouse('GZ');
		$this->_view['user'] = User::find('parent_id=? or id=?', Q::ini('custom_flag/info/warehouse_manager/value'), Q::ini('custom_flag/info/warehouse_manager/value'))->asArray()->getAll();
		$url_arr = Helper_BSS_Normal::buildCondition();
		$url_arr['trash_status'] = Q::ini('custom_flag/sales_order_trash_status/normal/value');
		$url_arr['order_operate_status'] = true;
		$url_arr['warehouse_id'] = Warehouse::getDefaultWarehouseId();
		$result = Sales_Order::search($url_arr, $cp, $ps, 'unix_timestamp(sales_order.sales_time) asc');
		if ($result['ack'] == SUCCESS)
		{
			$sales_order = $result['data'];
			$page = new Helper_BSS_Page($result['pagination'], url('Storage::Sales/OperateList', $url_arr));
			$this->_view['page'] = $page->getPage();
			Sales_Order_Notes::getOrderNotes($sales_order);
			Sales_Order_Item_Attribute::getSalesOrderItemAttr($sales_order);
			Sales_Order::checkWarning($sales_order);
			$this->_view['sales_order'] = $sales_order;
			$where = Sales_Order::buildSearchWhere($url_arr);
			$postage = QDB::getConn()->execute('select sum(weight) as weight, sum(sales_order.postage) as postage_amount, sum(sales_order.postage*sales_order.postage_currency_rate) as postage_amount_cny, currency.code from sales_order left join sales_order_customer_info on sales_order_customer_info.sales_order_id=sales_order.id left join currency on currency.id=sales_order.postage_currency_id where ' . $where . ' and sales_order.postage_currency_id>0 group by sales_order.postage_currency_id')->fetchAll();
			$this->_view['postage'] = $postage;
			$this->_view['url_arr_json'] = json_encode($url_arr);
		}
	}
	
	function actionAssignList()
	{
		$this->_view['title'] = '配货列表';
		$this->_view['shipping_method'] = Shipping_Method::getShippingMethodByWarehouse('GZ');
		$cp = isset($_GET['cp']) ? $_GET['cp'] : 1;
		$ps = isset($_GET['ps']) ? $_GET['ps'] : 10;
		$url_arr = Helper_BSS_Normal::buildCondition();
		$url_arr['trash_status'] = Q::ini('custom_flag/sales_order_trash_status/normal/value');
		$url_arr['order_status'][Q::ini('custom_flag/sales_order_handle_status/checkout/value')] = Q::ini('custom_flag/sales_order_handle_status/checkout/value');
		$url_arr['warehouse_id'] = Warehouse::getDefaultWarehouseId();
		$result = Sales_Order::search($url_arr, $cp, $ps, 'unix_timestamp(sales_order.sales_time) asc');
		if ($result['ack'] == SUCCESS)
		{
			$sales_order = $result['data'];
			$page = new Helper_BSS_Page($result['pagination'], url('Storage::Sales/AssignList', $url_arr));
			$this->_view['page'] = $page->getPage();
			Sales_Order_Notes::getOrderNotes($sales_order);
			Sales_Order_Item_Attribute::getSalesOrderItemAttr($sales_order);
			Sales_Order::checkWarning($sales_order);
			$this->_view['sales_order'] = $sales_order;
		}
	}
	
	function actionAssignAll()
	{
		$this->_view['title'] = '全部配货';
		$url_arr['trash_status'] = Q::ini('custom_flag/sales_order_trash_status/normal/value');
		$url_arr['order_status'][Q::ini('custom_flag/sales_order_handle_status/checkout/value')] = Q::ini('custom_flag/sales_order_handle_status/checkout/value');
		$url_arr['warehouse_id'] = Warehouse::getDefaultWarehouseId();
		$where = Sales_Order::buildSearchWhere($url_arr);
		$sales_order_ids = QDB::getConn()->execute('select id from sales_order where ' . $where . ' order by make_time asc')->fetchCol('id');
		$result = Sales_order::changeHandleStatusFromCheckoutToAssigned($sales_order_ids);
		if ($result['ack'] == SUCCESS)
		{
			return $this->_redirectMessage('配货成功', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
		}
		else
		{
			return $this->_redirectMessage('配货部分失败', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
		}
	}
	
	function actionAssignByChecked()
	{
		$this->_view['title'] = '确认配货';
		if ($this->_context->isGET())
		{
			$sales_order_ids = explode(',', $_GET['ids']);
			$result = Sales_order::changeHandleStatusFromCheckoutToAssigned($sales_order_ids);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('配货成功', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('配货部分失败', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
			}
		}
	}
	
	function actionMultiHold()
	{
		$this->_view['title'] = '批量仓库滞留';
		$ids = explode(',', $_GET['ids']);
		if ($ids)
		{
			$result = Sales_Order::changeHandleStatusToStorageHold($ids);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('滞留成功', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('滞留部分失败', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
			}
		}
	}
	
	function actionMultiToCheckOut()
	{
		$this->_view['title'] = '返回销售确认';
		$ids = explode(',', $_GET['ids']);
		if ($ids)
		{
			$result = Sales_Order::changeHandleStatusFromStorageHoldToCheckout($ids);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('确认成功', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('确认部分失败', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
			}
		}
	}
	
	function actionMultiToSalesHold()
	{
		$this->_view['title'] = '返回销售滞留';
		$ids = explode(',', $_POST['id']);
		if ($ids)
		{
			$result = Sales_Order::changeHandleStatusFromStorageHoldToSalesHold($ids, $_POST['notes_content']);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('滞留成功', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('确认部分失败', $result['message'], $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
	}

	function actionPrint()
	{
		$this->_view['title'] = '打印拣货单';
		$ids = explode(',', $_POST['ids']);
		$order = Sales_Order::find('sales_order.id in (?) and (sales_order.handle_status=? or sales_order.handle_status=?) and sales_order.trash_status=?', $ids, Q::ini('custom_flag/sales_order_handle_status/assigned/value'), Q::ini('custom_flag/sales_order_handle_status/printed/value'), Q::ini('custom_flag/sales_order_trash_status/normal/value'))->asArray()->getAll();
		$products = $order_ids = array();
		if ($order)
		{
			if (isset($_POST['type']) && $_POST['type'])
			{
				foreach ($order as $o)
				{
					if ($o['product_quantity'] <> 1)
					{
						return $this->_redirectMessage('打印失败', '订单：' . $o['number'] . ' 不是单个产品订单，请仔细检查！', $_SERVER['HTTP_REFERER']);
					}
				}
				foreach ($order as $o)
				{
					QDB::getConn()->execute('update sales_order set handle_status=' . Q::ini('custom_flag/sales_order_handle_status/printed/value') . ', print_user_id=' . CURRENT_USER_ID . ', print_time=\'' . CURRENT_DATETIME . '\', pick_user_id=' . $_POST['pick_user_id'] . ' where id=' . $o['id']);
					$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $o['id'])->asArray()->getAll();
					foreach ($item as $i)
					{
						if ( ! array_key_exists($i['product_basic_id']. '_' . $o['warehouse_id'], $products))
						{
							$product_warehouse = Product_Warehouse::find('product_basic_id=? and warehouse_id=?', $i['product_basic_id'], $o['warehouse_id'])->joinLeft('product_basic', 'name', 'product_basic.id=product_warehouse.product_basic_id')->asArray()->getOne();
							$products[$i['product_basic_id'] . '_' . $o['warehouse_id']] = array('number' => $product_warehouse['storage_number'], 'name' => $product_warehouse['name'], 'shelf_position' => $product_warehouse['shelf_position'] . ' ' . $product_warehouse['product_feature'], 'quantity' => 0);
						}
						$products[$i['product_basic_id'] . '_' .$o['warehouse_id']]['quantity']++;
					}
				}
				$products = Helper_BSS_Array::SortByValue($products, 'shelf_position');
				$this->_view['products'] = $products;
			}
			else
			{
				foreach ($order as $o)
				{
					QDB::getConn()->execute('update sales_order set handle_status=' . Q::ini('custom_flag/sales_order_handle_status/printed/value') . ', print_user_id=' . CURRENT_USER_ID . ', print_time=\'' . CURRENT_DATETIME . '\', pick_user_id=' . $_POST['pick_user_id'] . ' where id=' . $o['id']);
					$order_ids[] = $o['id'];
				}
				if ($order_ids)
				{
					OLM_TemplatePrint::standard($order_ids);
					exit;
				}
			}
		}
		else
		{
			return $this->_redirectMessage('没有符合订单', '正在返回..', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionPrintAddress()
	{
		$this->_view['title'] = '打印地址单';
		$order = Sales_Order::find('id=? and (handle_status=? or handle_status=?)', $_GET['id'], Q::ini('custom_flag/sales_order_handle_status/printed/value'), Q::ini('custom_flag/sales_order_handle_status/printed_address/value'))->getOne();
		if ($order['id'])
		{
			$shipping_method = Shipping_Method::find('id=?', $order['shipping_method'])->asArray()->getOne();
			$result = OLM_Address::$shipping_method['address_model']($order['id']);
			if ($result['ack'] == SUCCESS)
			{
				$order->handle_status = Q::ini('custom_flag/sales_order_handle_status/printed_address/value');
				$order->print_address_user_id = CURRENT_USER_ID;
				$order->print_address_time = CURRENT_DATETIME;
				$order->save();
				header('Content-Type: application/pdf');
				header('Cache-Control: private, must-revalidate, post-check=0, max-age=1');
				header('Pragma: public');
				echo $result['label'];
				exit;
			}
			else
			{
				echo $result['message'];
			}
		}
		else
		{
			echo '找不到合适的订单';
		}
		exit;
	}
	
	function actionPrintEMS()
	{
		$this->_view['title'] = '打印EMS';
		$ids = explode(',', $_POST['ids']);
		if ($ids)
		{
			$result = OLM_TemplatePrint::EMS($ids);
			exit;
		}
	}
	
	function actionPrintDHL()
	{
		$this->_view['title'] = '打印DHL';
		$ids = explode(',', $_POST['ids']);
		if ($ids)
		{
			$result = OLM_TemplatePrint::DHL($ids);
			exit;
		}
	}
	
	function actionPrintSpecial()
	{
		$this->_view['title'] = '特殊打印';
	}
	
	function actionPrintSpecialAddress()
	{
		$this->_view['title'] = '特殊打印地址单';
		$order = Sales_Order::find('number=? or tracking_number=?', $_GET['number'], $_GET['number'])->asArray()->getAll();
		if (count($order))
		{
			if (count($order) == 1)
			{
				$order = $order[0];
				$shipping_method = Shipping_Method::find('id=?', $order['shipping_method'])->asArray()->getOne();
				$result = OLM_Address::$shipping_method['address_model']($order['id']);
				if ($result['ack'] == SUCCESS)
				{
					header('Content-Type: application/pdf');
					header('Cache-Control: private, must-revalidate, post-check=0, max-age=1');
					header('Pragma: public');
					echo $result['label'];
					exit;
				}
				else
				{
					echo $order['number'] . $result['message'];
				}
			}
			else
			{
				echo '有多张订单';
			}
		}
		else
		{
			echo '没有符合的地址单';
		}
	}
	
	function actionPrintByExternalViaOrderNumber()
	{
		$this->_view['title'] = '外部打印由订单号';
		if ($_GET['shipping_method'])
		{
			$warehouse_id = Warehouse::getDefaultWarehouseId();
			$order = Sales_Order::find('number=? and warehouse_id=?', $_GET['number'], $warehouse_id)->getOne();
			if ($order['id'])
			{
				if ($order['trash_status'] == Q::ini('custom_flag/sales_order_trash_status/normal/value'))
				{
					if ($order['handle_status'] == Q::ini('custom_flag/sales_order_handle_status/printed/value') || $order['handle_status'] == Q::ini('custom_flag/sales_order_handle_status/printed_address/value'))
					{
						if ($order['handle_status'] == Q::ini('custom_flag/sales_order_handle_status/printed_address/value') && empty($_GET['repeat']))
						{
							echo json_encode(array('ack' => FAILURE, 'message' => '该订单已打印', 'order' => '', 'label' => ''));exit;
						}
						$shipping_method = Shipping_Method::find('id=?', $order['shipping_method'])->asArray()->getOne();
						if (in_array($order['shipping_method'], Q::normalize($_GET['shipping_method'], ",")))
						{
							$result = OLM_Address::$shipping_method['address_model']($order['id']);
							if ($result['ack'] == SUCCESS)
							{
								$order->handle_status = Q::ini('custom_flag/sales_order_handle_status/printed_address/value');
								$order->print_address_user_id = CURRENT_USER_ID;
								$order->print_address_time = CURRENT_DATETIME;
								$order->save();
								$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $order['id'])
									->joinLeft('product_basic', '', 'product_basic.id=sales_order_item.product_basic_id')
									->setColumns('product_basic.number, sales_order_item.quantity')->asArray()->getAll();
								$shop = Shop::find('id=?', $order['shop_id'])->asArray()->getOne();
								$sales_order = array(
									'id' => $order['id'],
									'number' => $order['number'],
									'gift_card' => $shop['gift_card'],
									'shipping_method' => $order['shipping_method'],
									'item' => $item
								);
								echo json_encode(array('ack' => SUCCESS, 'message' => '', 'order' => $sales_order, 'label' => base64_encode($result['label'])));
							}
							else
							{
								echo json_encode(array('ack' => FAILURE, 'message' => $result['message'], 'order' => '', 'label' => ''), JSON_UNESCAPED_UNICODE);
							}
						}
						else
						{
							echo json_encode(array('ack' => FAILURE, 'message' => '该订单邮寄方式（' . $shipping_method['name'] . '）不符', 'label' => ''), JSON_UNESCAPED_UNICODE);
						}
					}
					else
					{
						echo json_encode(array('ack' => FAILURE, 'message' => '该订单状态（' . Helper_BSS_Normal::getIniOne('sales_order_handle_status', 'value', $order['handle_status'], 'name') . '）不符', 'label' => ''), JSON_UNESCAPED_UNICODE);
					}
				}
				else
				{
					echo json_encode(array('ack' => FAILURE, 'message' => '该订单已废弃', 'order' => '', 'label' => ''), JSON_UNESCAPED_UNICODE);
				}
			}
			else
			{
				echo json_encode(array('ack' => FAILURE, 'message' => '订单编号错误', 'order' => '', 'label' => ''), JSON_UNESCAPED_UNICODE);
			}
		}
		else
		{
			echo json_encode(array('ack' => FAILURE, 'message' => '邮寄方式没有选择', 'order' => '', 'label' => ''), JSON_UNESCAPED_UNICODE);
		}
		exit;
	}
	
	function actionPrintByExternalViaProductNumber()
	{
		$this->_view['title'] = '外部打印由产品编号';
		if ($_GET['shipping_method'])
		{
			$warehouse_id = Warehouse::getDefaultWarehouseId();
			$order = Sales_Order_Item::find('sales_order.product_quantity=1 and warehouse_id=? and sales_order.shipping_method in (' . $_GET['shipping_method'] . ') and product_basic.number=? and sales_order.trash_status=? and sales_order.handle_status=?', $warehouse_id, $_GET['number'], Q::ini('custom_flag/sales_order_trash_status/normal/value'), Q::ini('custom_flag/sales_order_handle_status/printed/value'))
				->joinLeft('sales_order', '', 'sales_order.id=sales_order_item.sales_order_id')
				->joinLeft('product_basic', '', 'product_basic.id=sales_order_item.product_basic_id')
				->setColumns('sales_order.*')->asArray()->getOne();
			if ($order['id'])
			{
				$shipping_method = Shipping_Method::find('id=?', $order['shipping_method'])->asArray()->getOne();
				$result = OLM_Address::$shipping_method['address_model']($order['id']);
				if ($result['ack'] == SUCCESS)
				{
					QDB::getConn()->execute('update sales_order set handle_status=' . Q::ini('custom_flag/sales_order_handle_status/printed_address/value') . ',print_address_user_id=' . CURRENT_USER_ID . ',print_address_time=\'' . CURRENT_DATETIME . '\' where id=' . $order['id']);
					$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $order['id'])
						->joinLeft('product_basic', '', 'product_basic.id=sales_order_item.product_basic_id')
						->setColumns('product_basic.number, sales_order_item.quantity')->asArray()->getAll();
					$shop = Shop::find('id=?', $order['shop_id'])->asArray()->getOne();
					$sales_order = array(
						'id' => $order['id'],
						'number' => $order['number'],
						'gift_card' => $shop['gift_card'],
						'shipping_method' => $order['shipping_method'],
						'item' => $item
					);
					echo json_encode(array('ack' => SUCCESS, 'message' => '', 'order' => $sales_order, 'label' => base64_encode($result['label'])));
				}
				else
				{
					echo json_encode(array('ack' => FAILURE, 'message' => $order['number'] . $result['message'], 'order' => '', 'label' => ''));
				}
			}
			else
			{
				echo json_encode(array('ack' => FAILURE, 'message' => '没有符合的订单', 'order' => '', 'label' => ''));
			}
		}
		else
		{
			echo json_encode(array('ack' => FAILURE, 'message' => '邮寄方式没有选择', 'order' => '', 'label' => ''));
		}
		exit;
	}
	
	function actionAddNotes()
	{
		$this->_view['title'] = '添加销售订单备注';
		if ($this->_context->isPOST())
		{
			$result = Sales_Order_Notes::create($_POST['id'], $_POST['notes_content'], Q::ini('custom_flag/sales_order_notes_type/warehouse/value'));
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('添加成功', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('添加失败', '该订单不存在', $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
		return $this->_redirectMessage('操作失败', '不是提交动作', $_SERVER['HTTP_REFERER'], FAILURE);
	}
	
	function actionExpressHK()
	{
		$this->_view['title'] = '同步香港DHL';
		$sales_order_ids = explode(',', $_POST['info']);
		if ($sales_order_ids)
		{
			$result = Sales_Order::HKExpressSync($sales_order_ids);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('同步成功', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('同步部分失败', $result['message'], $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
		else
		{
			return $this->_redirectMessage('没有符合条件订单', '请检查订单是否符合条件', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}

	function actionExpressJH()
	{
		$this->_view['title'] = '同步均辉';
		$sales_order_ids = explode(',', $_POST['info']);
		if ($sales_order_ids)
		{
			$result = Sales_Order::JHExpressSync($sales_order_ids, $_POST['order_type']);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('同步成功', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('同步失败', $result['message'], $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
		else
		{
			return $this->_redirectMessage('没有符合条件订单', '请检查订单是否符合条件', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionExpressMC()
	{
		$this->_view['title'] = '同步米巢';
		$sales_order_ids = explode(',', $_POST['info']);
		if ($sales_order_ids)
		{
			$result = Sales_Order::MCExpressSync($sales_order_ids, $_POST['order_type']);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('同步成功', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('同步失败', $result['message'], $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
		else
		{
			return $this->_redirectMessage('没有符合条件订单', '请检查订单是否符合条件', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionExpressSFC()
	{
		$this->_view['title'] = '同步三态';
		$sales_order_ids = explode(',', $_POST['info']);
		if ($sales_order_ids)
		{
			$result = Sales_Order::SFCExpressSync($sales_order_ids, $_POST['order_type']);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('同步成功', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('同步失败', $result['message'], $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
		else
		{
			return $this->_redirectMessage('没有符合条件订单', '请检查订单是否符合条件', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionExpress4PX()
	{
		$this->_view['title'] = '同步4PX';
		$sales_order_ids = explode(',', $_POST['info']);
		if ($sales_order_ids)
		{
			$result = Sales_Order::FPXExpressSync($sales_order_ids, $_POST['order_type']);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('同步成功', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('同步失败', $result['message'], $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
		else
		{
			return $this->_redirectMessage('没有符合条件订单', '请检查订单是否符合条件', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionExpressBY()
	{
		$this->_view['title'] = '同步贝易';
		$sales_order_ids = explode(',', $_POST['info']);
		$post_type = isset($_POST['post_type']) ? $_POST['post_type'] : 1;
		if ($sales_order_ids)
		{
			$result = Sales_Order::BYExpressSync($sales_order_ids, $_POST['order_type'], $post_type);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('同步成功', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('同步失败', $result['message'], $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
		else
		{
			return $this->_redirectMessage('没有符合条件订单', '请检查订单是否符合条件', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionExpressQT()
	{
		$this->_view['title'] = '同步全通';
		$sales_order_ids = explode(',', $_POST['info']);
		if ($sales_order_ids)
		{
			$result = Sales_Order::QTExpressSync($sales_order_ids, $_POST['order_type']);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('同步成功', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('同步失败', $result['message'], $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
		else
		{
			return $this->_redirectMessage('没有符合条件订单', '请检查订单是否符合条件', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionExpressBpost()
	{
		$this->_view['title'] = '同步比利时邮政';
		$sales_order_ids = Q::normalize($_POST['info'], ',');
		if ($sales_order_ids)
		{
			$result = Sales_Order::bpostExpressSync($sales_order_ids, $_POST['order_type']);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('同步成功', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('同步失败', $result['message'], $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
		else
		{
			return $this->_redirectMessage('没有符合条件订单', '请检查订单是否符合条件', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionExpressBUB()
	{
		$this->_view['title'] = '同步贝邮宝';
		$sales_order_ids = Q::normalize($_POST['info'], ',');
		if ($sales_order_ids)
		{
			$result = Sales_Order::BUBExpressSync($sales_order_ids, $_POST['order_type']);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('同步成功', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('同步失败', $result['message'], $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
		else
		{
			return $this->_redirectMessage('没有符合条件订单', '请检查订单是否符合条件', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionExpressSF()
	{
		$this->_view['title'] = '同步顺丰';
		$sales_order_ids = Q::normalize($_POST['info'], ',');
		if ($sales_order_ids)
		{
			$result = Sales_Order::SFExpressSync($sales_order_ids, $_POST['order_type']);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('同步成功', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('同步部分失败', $result['message'], $_SERVER['HTTP_REFERER'], PARTIAL_FAILURE);
			}
		}
		else
		{
			return $this->_redirectMessage('没有符合条件订单', '请检查订单是否符合条件', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionExpressAE()
	{
		$this->_view['title'] = '同步速卖通';
		$sales_order_ids = Q::normalize($_POST['info'], ',');
		if ($sales_order_ids)
		{
			$result = Sales_Order::AEExpressSync($sales_order_ids, $_POST['order_type']);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('同步成功', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('同步部分失败', $result['message'], $_SERVER['HTTP_REFERER'], PARTIAL_FAILURE);
			}
		}
		else
		{
			return $this->_redirectMessage('没有符合条件订单', '请检查订单是否符合条件', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionGetAEOrderTrackingNum()
	{
		$this->_view['title'] = '获取速卖通追踪号';
		if (isset($_GET['ids']) && $_GET['ids'])
		{
			$sales_order_ids = Q::normalize($_GET['ids'], ',');
			$message = '';
			foreach ($sales_order_ids as $id)
			{
				$result = Sales_Order::GetAEOrderTrackingNum($id);
				if ($result['ack'] == 'FAILURE')
				{
					$message .= $result['message'] . "\n";
				}
			}
			if ($message)
			{
				return $this->_redirectMessage('获取同步部分失败', $message, $_SERVER['HTTP_REFERER'], PARTIAL_FAILURE);
			}
			else
			{
				return $this->_redirectMessage('获取同步成功', '', $_SERVER['HTTP_REFERER'], SUCCESS);
			}
		}
		else
		{
			return $this->_redirectMessage('获取失败！', '没有符合条件订单', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionOutList()
	{
		$this->_view['title'] = '出库单列表';
		$this->_view['shop'] = Shop::getActiveShop();
		$this->_view['shipping_method'] = Shipping_Method::getShippingMethodByWarehouse('GZ');;
		if (isset($_GET['is_search']))
		{
			$cp = isset($_GET['cp']) ? $_GET['cp'] : 1;
			$ps = isset($_GET['ps']) ? $_GET['ps'] : 10;
			$url_arr = Helper_BSS_Normal::buildCondition();
			$url_arr['trash_status'] = Q::ini('custom_flag/sales_order_trash_status/normal/value');
			$url_arr['order_status'][Q::ini('custom_flag/sales_order_handle_status/shipped/value')] = Q::ini('custom_flag/sales_order_handle_status/shipped/value');
			$url_arr['order_status'][Q::ini('custom_flag/sales_order_handle_status/return/value')] = Q::ini('custom_flag/sales_order_handle_status/return/value');
			$url_arr['shipping_status'] = Q::ini('custom_flag/sales_order_shipping_status/shipped/value');
			$result = Sales_Order::search($url_arr, $cp, $ps, 'sales_order.id desc');
			if ($result['ack'] == SUCCESS)
			{
				$order = $result['data'];
				$page = new Helper_BSS_Page($result['pagination'], url('Storage::Sales/OutList', $url_arr));
				$this->_view['page'] = $page->getPage();
				$where = Sales_Order::buildSearchWhere($url_arr);
				$postage = QDB::getConn()->execute('select sum(weight) as weight, sum(sales_order.postage) as postage_amount, sum(sales_order.postage*sales_order.postage_currency_rate) as postage_amount_cny, currency.code from sales_order left join sales_order_customer_info on sales_order_customer_info.sales_order_id=sales_order.id left join currency on currency.id=sales_order.postage_currency_id where ' . $where . ' and sales_order.postage_currency_id>0 group by sales_order.postage_currency_id')->fetchAll();
				$this->_view['postage'] = $postage;
				$this->_view['order'] = $order;
			}
		}
	}
	
	function actionMultiOut()
	{
		$this->_view['title'] = '批量出库';
		$ids = explode(',', $_POST['ids']);
		if ($ids)
		{
			$result = Sales_Order::out($ids);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('出库成功！', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('出库部分失败！', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
			}
		}
	}
	
	function actionExpressNumber()
	{
		$id = $_REQUEST['id'];
		$lsp_number = $_REQUEST['number'];
		QDB::getConn()->execute('update sales_order set lsp_number=\'' . $lsp_number . '\' where sales_order_id=' . $id);
		echo 1;exit;
	}
	
	function actionTrackingNumber()
	{
		$id = $_REQUEST['id'];
		$tracking_number = $_REQUEST['number'];
		QDB::getConn()->execute('update sales_order set tracking_number=\'' . $tracking_number .'\' where id='.$id);
		echo 1;exit;
	}
	
	function actionImportTrackingNumber()
	{
		$this->_view['title'] = '导入追踪号';
	}
	
	function actionImportTrackingNumberFormSave()
	{
		$this->_view['title'] = '表单导入追踪号（保存）';
		if (isset($_REQUEST['numbers']) && $_REQUEST['numbers'])
		{
			$numbers = Q::Normalize($_REQUEST['numbers'], "\n");
			if(count($numbers) % 2 == 0)
			{
				$numbers = array_chunk($numbers, 2);
				$numbers_error = array();
				$success_number = $failure_number = 0;
				foreach ($numbers as $n)
				{
					$sales_order = Sales_Order::find('number=?', $n[0])->getOne();
					if ($sales_order['id'])
					{
						$sales_order->tracking_number = $n[1];
						$sales_order->Save();
						$success_number++;
					}
					else
					{
						$numbers_error[] = $n[0];
						$failure_number++;
					}
				}
				if(! $numbers_error)
				{
					echo json_encode(array('ack' => SUCCESS, 'message' => '导入成功', 'success_number' => $success_number, 'failure_number' => $failure_number));
				}
				else
				{
					echo json_encode(array('ack' => SUCCESS, 'message' => '导入部分失败,编号为' . implode($numbers_error, ','), 'success_number' => $success_number, 'failure_number' => $failure_number));
				}
			}
			else
			{
				echo json_encode(array('ack' => FAILURE, 'message' => '订单编号与追踪号不一致', 'success_number' => 0, 'failure_number' => 0));
			}
		}
		else
		{
			echo json_encode(array('ack' => FAILURE, 'message' => '输入框不能为空', 'success_number' => 0, 'failure_number' => 0));
		}
	}
	
	function actionImportFLYTTrackingNumberSave()
	{
		$this->_view['title'] = '导入飞特追踪号（保存）';
		if ($this->_context->isPOST())
		{
			$upload_result = Upload_Files::uploadFile('FLYT_tracking_number', Q::ini('custom_flag/upload_file_type/tracking_number/value'));
			if ($upload_result['ack'] == SUCCESS)
			{
				$file_name = $upload_result['path'];
				$handle = fopen($file_name,'r',false);
				$filesize = filesize($file_name);
				$data = array();
				while ($row = Helper_BSS_CSV::fgetcsvReg($handle, $filesize, ','))
				{
					$data[] = $row;
				}
				fclose($handle);
				$key = array_shift($data);
				$kdata = array();
				foreach ($data as $d)
				{
					$temp = array();
					foreach ($key as $k => $kv)
					{
						$temp[] = trim($d[$k]);
					}
					$kdata[] = $temp;
				}
				foreach ($kdata as $kd)
				{
					$sales_order = Sales_Order::find('number=?', trim($kd[2]))->getOne();
					if ($sales_order['id'])
					{
						$sales_order->tracking_number = trim($kd[1]);
						$sales_order->save();
					}
				}
			}
		}
		return $this->_redirectMessage('导入成功', '返回导入页面', url('Storage::Sales/ImportTrackingNumber'));
	}
	
	function actionImportTrackingNumberSave()
	{
		$this->_view['title'] = '导入追踪号（保存）';
		if ($this->_context->isPOST())
		{
			$upload_result = Upload_Files::uploadFile('tracking_number', Q::ini('custom_flag/upload_file_type/tracking_number/value'));
			if ($upload_result['ack'] == SUCCESS)
			{
				$file_name = $upload_result['path'];
				$handle = fopen($file_name, "r");
			}
			$file_type = substr(strrchr($file_name, '.'), 1);
			if ($file_type == 'xls')
			{
				$data = Helper_BSS_XLS::xlsFileToArray($file_name, $handle);
			}
			else
			{
				$buffer = array();
				if ($handle)
				{
					while ( ! feof($handle))
					{
						$buffer[] = fgets($handle, 4096);
					}
				}
				if ($buffer)
				{
					$data = array_chunk($buffer, 2);
				}
				else
				{
					$data = array();
				}
			}
			foreach ($data as $d)
			{
				$d = array_values($d);
				$order = Sales_Order::find('number=?', trim($d[0]))->getOne();
				if ($order['id'])
				{
					$order->tracking_number = trim($d[1]);
					$order->save();
				}
			}
		}
		return $this->_redirectMessage('导入成功', '返回导入页面', url('Storage::Sales/ImportTrackingNumber'), $result['ack']);
	}
	
	function actionReturnList()
	{
		$this->_view['title'] = '销售退货单列表';
		$shop = Shop::getActiveShop();
		$this->_view['shop'] = $shop;
		$cp = isset($_GET['cp']) ? $_GET['cp'] : 0;
		$ps = isset($_GET['ps']) ? $_GET['ps'] : 10;
		$url_arr = Helper_BSS_Normal::buildCondition();
		$url_arr['warehouse_id'] = Warehouse::getDefaultWarehouseId();
		$result = Sales_Return::search($url_arr, $cp, $ps);
		if ($result['ack'] == SUCCESS)
		{
			$sales_return = $result['data'];
			$page = new Helper_BSS_Page($result['pagination'], url('Storage::sales/ReturnList', $url_arr));
			$this->_view['page'] = $page->getPage();
			Sales_Order_Notes::getOrderNotes($sales_return);
			$this->_view['sales_return'] = $sales_return;
		}
	}
	
	function actionReturnInfo()
	{
		$this->_view['title'] = '退货详细信息';
		if ($_GET['id'])
		{
			$return = Sales_Return::find('id=?', $_GET['id'])->asArray()->getOne();
			$sales_order_id = $return['sales_order_id'];
			$return['item'] = Sales_return_item::find('sales_return_id=?', $return['id'])
				->joinLeft('product_basic', 'number as product_number, name as product_name', 'product_basic.id=sales_return_item.product_basic_id')
				->asArray()->getAll();
			$sales_order = Sales_Order::find('sales_order.id=?', $sales_order_id)->asArray()->getOne();
			$shop = Shop::find('id=?', $sales_order['shop_id'])->asArray()->getOne();
			$this->_view['shop'] = $shop;
			$this->_view['sales_return'] = $return;
			$this->_view['sales_order'] = $sales_order;
			$this->_view['return'] = $return['item'];
		}
	}
	
	function actionReturnStoraged()
	{
		$this->_view['title'] = '退货单审核入库';
		$sales_return_ids = explode(',', $_GET['ids']);
		if ($sales_return_ids)
		{
			$result = Sales_Return::storageAudit($sales_return_ids);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('审核成功', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('部分审核失败', $result['message'], $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
	}
	
	function actionWeigh()
	{
		$this->_view['title'] = '称重';
		if (isset($_GET['number']) && $_GET['number'])
		{
			$order = Sales_Order::find('(sales_order.number=? or sales_order.tracking_number=? or sales_order.lsp_number=?) and (sales_order.handle_status=? or sales_order.handle_status=?)', trim($_GET['number']), trim($_GET['number']), trim($_GET['number']), Q::ini('custom_flag/sales_order_handle_status/printed_address/value'), Q::ini('custom_flag/sales_order_handle_status/weighed/value'))
				->joinLeft('sales_order_customer_info', 'fullname, country', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->joinLeft('user', 'name as user_name', 'user.id=sales_order.sales_user_id')
				->joinLeft('shop', 'name as shop_name', 'shop.id=sales_order.shop_id')
				->joinLeft('shipping_method', 'name as shipping_method_name', 'shipping_method.id=sales_order.shipping_method')
				->joinLeft('currency', 'currency.symbol as postage_currency_symbol', 'currency.id=sales_order.postage_currency_id')
				->asArray()->getAll();
			if ($order)
			{
				if (count($order) == 1)
				{
					Sales_Order_Notes::getOrderNotes($order);
					Sales_Order_Item_Attribute::getSalesOrderItemAttr($order);
					$this->_view['order'] = $order[0];
				}
				else
				{
					$this->_view['wrong'] = '多张订单';
				}
			}
			else
			{
				$this->_view['wrong'] = '没有找到订单';
			}
		}
	}
	
	function actionWeighSave()
	{
		$this->_view['title'] = '称重（ajax保存）';
		$order_id = $_REQUEST['order_id'];
		$weight = trim($_REQUEST['weight']);
		$order = Sales_Order::find('id=?', $order_id)->asArray()->getOne();
		if ($order['id'])
		{
			$result = Sales_Order::weigh($order['number'], $order['shipping_method'], $weight, CURRENT_USER_ID);
			$order = Sales_Order::find('sales_order.id=?', $order['id'])
				->joinLeft('currency', 'currency.symbol as postage_currency_symbol', 'currency.id=sales_order.postage_currency_id')
				->asArray()->getOne();
			if ($result['ack'] == SUCCESS)
			{
				echo json_encode(array('ack' => 1, 'message' => '', 'postage' => $order['postage_currency_symbol'] . sprintf('%.2f', $order['postage'])));
				exit;
			}
			else
			{
				echo json_encode(array('ack' => -1, 'message' => $result['message'], 'postage' => $order['postage_currency_symbol'] . sprintf('%.2f', $order['postage'])));
				exit;
			}
		}
	}
	
	function actionWeighByOther()
	{
		$this->_view['title'] = '称重（通过外部程序）';
		if (isset($_GET['number']) && $_GET['number'] && isset($_GET['shipping_method']) && $_GET['shipping_method'] && isset($_GET['weight']))
		{
			$has_g =  strrchr($_GET['weight'], 'g');
			$weight = $has_g ? trim(substr($_GET['weight'], 0, -1)) : trim($_GET['weight']);
			$pack_user_id = isset($_GET['pack_user_id']) ? $_GET['pack_user_id'] : 0;
			$order = Sales_Order::find('number=? or tracking_number=? or lsp_number=?', $_GET['number'], $_GET['number'], $_GET['number'])->asArray()->getAll();
			if (count($order) == 1 && $order[0]['handle_status'] == Q::ini('custom_flag/sales_order_handle_status/weighed/value') && empty($_GET['repeat']))
			{
				echo json_encode(array('ack' => FAILURE, 'message' => '该订单重复称重！', 'order_number' => '', 'weight' => '', 'estimated_weight' => '', 'shipping_fee' => '', 'postage_currency_symbol' => ''));
				exit;
			}
			$result = Sales_Order::weigh($_GET['number'], $_GET['shipping_method'], $weight, $pack_user_id);
			echo json_encode($result);exit;
		}
		else
		{
			echo json_encode(array('ack' => FAILURE, 'message' => '信息不全', 'order_number' => '', 'weight' => '', 'estimated_weight' => '', 'shipping_fee' => '', 'postage_currency_symbol' => ''));
			exit;
		}
	}
	
	function actionExportOrderWeightInfo()
	{
		$this->_view['title'] = '导出订单重量信息';
		set_time_limit(0);
		if (isset($_REQUEST['ids']) || $_REQUEST['url_arr_json'])
		{
			$where = isset($_REQUEST['url_arr_json']) ? Sales_Order::buildSearchWhere(json_decode($_REQUEST['url_arr_json'], true)) : 'sales_order.id in (' . $_REQUEST['ids'] . ')';
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->joinLeft('country', '', 'country.en_name=sales_order_customer_info.country')
				->setColumns('sales_order.number, sales_order.weight, country.code as country_code')
				->asArray()->getAll();
			if ($result)
			{
				include Q::ini('custom_system/lib_dir').'PHPExcel.php';
				$phpexcel = new PHPExcel();
				$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
				$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
				$phpexcel->getProperties()->setTitle("重量信息表");
				$phpexcel->getProperties()->setSubject("重量信息表");
				$phpexcel->getProperties()->setDescription("重量信息表-运营支撑系统");
				$phpexcel->getProperties()->setKeywords("重量信息表");
				$phpexcel->getProperties()->setCategory("重量信息表");
				$phpexcel->setActiveSheetIndex(0);
				$phpexcel->getActiveSheet()->setTitle("重量信息表");
				$phpexcel->getActiveSheet()->setCellValue('A1', "产品编号");
				$phpexcel->getActiveSheet()->setCellValue('B1', "国家二字码");
				$phpexcel->getActiveSheet()->setCellValue('C1', "重量(g)");
				$phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
				$phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
				$phpexcel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
				$phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
				$phpexcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
				$phpexcel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true);
				$phpexcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$phpexcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$phpexcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$i = 2;
				foreach ($result as $r)
				{
					$phpexcel->getActiveSheet()->getCell('A'.$i)->setValueExplicit($r['number'], PHPExcel_Cell_DataType::TYPE_STRING);
					$phpexcel->getActiveSheet()->setCellValue('B'.$i, $r['country_code']);
					$phpexcel->getActiveSheet()->setCellValue('C'.$i, $r['weight']);
					$i++;
				}
				$outputFileName = "重量信息表.xls";
				$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
				header("Content-Type: application/vnd.ms-execl");
				header("Content-Type: application/octet-stream");
				header("Content-Type: application/download");
				header('Content-Disposition:inline;filename="'.$outputFileName.'"');
				header("Content-Transfer-Encoding: binary");
				header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
				header("Pragma: no-cache");
				$objWriter->save('php://output');
				exit;
			}
			else
			{
				$this->_redirectMessage('导出失败', '没有数据信息！', $_SERVER['HTTP_REFERER'], FAILURE);
			}
		}
		else
		{
			$this->_redirectMessage('导出失败', '请求参数有误！', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionExportJHOrderInfo()
	{
		$this->_view['title'] = '导出均辉订单模板';
		set_time_limit(300);
		$url_arr = json_decode($_REQUEST['url_arr_json'], true);
		if ( ! empty($url_arr))
		{
			$where = Sales_Order::buildSearchWhere($url_arr);
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->joinLeft('country', '', 'country.en_name=sales_order_customer_info.country')
				->setColumns('sales_order.number, sales_order.weight, sales_order.shipping_method, sales_order_customer_info.*, country.code as country_code')
				->asArray()->getAll();
			include Q::ini('custom_system/lib_dir').'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle("均辉订单模板表");
			$phpexcel->getProperties()->setSubject("均辉订单模板表");
			$phpexcel->getProperties()->setDescription("均辉订单模板表-运营支撑系统");
			$phpexcel->getProperties()->setKeywords("均辉订单模板");
			$phpexcel->getProperties()->setCategory("均辉订单模板");
			$phpexcel->setActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle("均辉订单模板");
			$phpexcel->getActiveSheet()->setCellValue('A1', "单号");
			$phpexcel->getActiveSheet()->setCellValue('B1', "申报价值*,带*号必填");
			$phpexcel->getActiveSheet()->setCellValue('C1', "件数*");
			$phpexcel->getActiveSheet()->setCellValue('D1', "收件人姓名*");
			$phpexcel->getActiveSheet()->setCellValue('E1', "地址*");
			$phpexcel->getActiveSheet()->setCellValue('F1', "地址2(可不填)");
			$phpexcel->getActiveSheet()->setCellValue('G1', "地址3可不填");
			$phpexcel->getActiveSheet()->setCellValue('H1', "城市*");
			$phpexcel->getActiveSheet()->setCellValue('I1', "国家(全称或二字码)*");
			$phpexcel->getActiveSheet()->setCellValue('J1', "邮编*");
			$phpexcel->getActiveSheet()->setCellValue('K1', "电话*");
			$phpexcel->getActiveSheet()->setCellValue('L1', "详细描述*");
			$phpexcel->getActiveSheet()->setCellValue('M1', "重量2KG以内,不要带KG*");
			$phpexcel->getActiveSheet()->setCellValue('N1', "品名*");
			$phpexcel->getActiveSheet()->setCellValue('O1', "挂号(0挂号，1不挂号)*");
			$phpexcel->getActiveSheet()->setCellValue('P1', "货架号可不填");
			$i = 2;
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'declared_value, declared_name_cn, declared_name_en', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$quantity = 0;
				$declared_value = 0;
				foreach ($item as $it)
				{
					$quantity += $it['quantity'];
					$declared_value += $it['declared_value'];
				}
				$phpexcel->getActiveSheet()->getCell('A'.$i)->setValueExplicit($r['number'], PHPExcel_Cell_DataType::TYPE_STRING);
				$phpexcel->getActiveSheet()->setCellValue('B'.$i, $declared_value);
				$phpexcel->getActiveSheet()->setCellValue('C'.$i, $quantity);
				$phpexcel->getActiveSheet()->setCellValue('D'.$i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('E'.$i, $r['street1']);
				$phpexcel->getActiveSheet()->setCellValue('F'.$i, $r['street2']);
				$phpexcel->getActiveSheet()->setCellValue('G'.$i, '');
				$phpexcel->getActiveSheet()->setCellValue('H'.$i, $r['city']);
				$phpexcel->getActiveSheet()->setCellValue('I'.$i, $r['country_code']);
				$phpexcel->getActiveSheet()->setCellValue('J'.$i, $r['zip']);
				$phpexcel->getActiveSheet()->setCellValue('K'.$i, $r['phone']);
				$phpexcel->getActiveSheet()->setCellValue('L'.$i, $r['number']);
				$phpexcel->getActiveSheet()->setCellValue('M'.$i, $r['weight']/1000);
				$phpexcel->getActiveSheet()->setCellValue('N'.$i, $item[0]['declared_name_en']);
				$phpexcel->getActiveSheet()->setCellValue('O'.$i, ($r['shipping_method'] == Shipping_Method::getShippingMethodByCode('GZ_R_DHL_Package')) ? 0 : 1);
				$phpexcel->getActiveSheet()->setCellValue('P'.$i, '');
				$i++;
			}
			$outputFileName = "JH.xls";
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			header("Content-Type: application/vnd.ms-execl");
			header("Content-Type: application/octet-stream");
			header("Content-Type: application/download");
			header('Content-Disposition:inline;filename="'.$outputFileName.'"');
			header("Content-Transfer-Encoding: binary");
			header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}
	
	function actionExportFLYTOrderInfo()
	{
		$this->_view['title'] = '导出飞特订单模板';
		set_time_limit(300);
		if (isset($_REQUEST['url_arr_json']) || isset($_REQUEST['ids']))
		{
			$where = isset($_REQUEST['url_arr_json']) ? Sales_Order::buildSearchWhere(json_decode($_REQUEST['url_arr_json'], true)) : 'sales_order.id in (' . $_REQUEST['ids'] . ')';
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->joinLeft('currency', '', 'currency.id=sales_order.currency_id')
				->setColumns('sales_order.number, sales_order.shipping_method, currency.code as currency_code, sales_order_customer_info.*')
				->asArray()->getAll();
			$data = "版本7_1\t目的地国家(必填)\t货运方式(必填)\t收件人(必填)\t包裹详情_英文1\t包裹详情_中文1\t数量1\t币种1\t单价1\t包裹详情_英文2\t包裹详情_中文2\t数量2\t币种2\t单价2\t包裹详情_英文3\t包裹详情_中文3\t数量3\t币种3\t单价3\t包裹详情_英文4\t包裹详情_中文4\t数量4\t币种4\t单价4\t包裹详情_英文5\t包裹详情_中文5\t数量5\t币种5\t单价5\t收件人Email\t地址1(必填)\t地址2\t州(省)\t城市(必填)\t邮编(必填)\t电话\tremark\tpackinfo1\tpackinfo2\tpackinfo3\tUSPS3Days是否挂号\t客户订单编号\n";
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'declared_value, declared_name_cn, declared_name_en', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$code = array(11 => 'FGMSN', 12 => 'FGMSR', 39 => 'THFGMSN', 40 => 'THFGMSR');
				$shipping_method = $code[$r['shipping_method']];
				$quantity = 0;
				if ($item)
				{
					foreach ($item as $it)
					{
						$quantity += $it['quantity'];
					}
					foreach ($r as $k => $v)
					{
						$r[$k] = str_replace('"', '""', $v);
					}
					$phone = ($r['phone'] === '') ? 0 : $r['phone'];
					$data .= "\t" . trim($r['country']) . "\t{$shipping_method}" . "\t" . trim($r['fullname']) . "\t{$item[0]['declared_name_en']}\t{$item[0]['declared_name_cn']}\t{$quantity}\t{$r['currency_code']}\t{$item[0]['declared_value']}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$r['email']}\t{$r['street1']}\t{$r['street2']}\t{$r['state']}\t{$r['city']}\t^{$r['zip']}\t^{$phone}\t{$r['number']}\t\t\t\t\t{$r['number']}\n";
				}
			}
			$data = iconv("UTF-8","UTF-16LE",$data);
			$data = "\xFF\xFE".$data;
			header("Content-type: text;");
			header("Content-Disposition: attachment; filename=" . date("YmdHis") . ".txt");
			header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
			header('Expires: 0');
			header('Pragma: public');
			echo $data;
			exit;
		}
	}
	
	function actionExportSYOrderInfo()
	{
		$this->_view['title'] = '导出顺邮模板';
		if (isset($_REQUEST['ids']) || isset($_REQUEST['url_arr_json']))
		{
			if (isset($_REQUEST['ids']))
			{
				$where = "sales_order.id in ({$_REQUEST['ids']})";
			}
			else
			{
				$url_arr = json_decode($_REQUEST['url_arr_json'], true);
				$where = Sales_Order::buildSearchWhere($url_arr);
			}
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->setColumns('sales_order.warehouse_id, sales_order.number, sales_order.shipping_method, sales_order.weight, sales_order.product_quantity, sales_order.tracking_number, sales_order_customer_info.*')
				->asArray()->getAll();
			include Q::ini('custom_system/lib_dir').'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle("订单导入模板");
			$phpexcel->getProperties()->setSubject("订单导入模板");
			$phpexcel->getProperties()->setDescription("订单导入模板-运营支撑系统");
			$phpexcel->getProperties()->setKeywords("订单导入模板");
			$phpexcel->getProperties()->setCategory("订单导入模板");
			$phpexcel->setActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle("订单导入模板");
			$phpexcel->getActiveSheet()->setCellValue('A1', "Shipping");
			$phpexcel->getActiveSheet()->setCellValue('B1', "Weight");
			$phpexcel->getActiveSheet()->setCellValue('C1', "Length");
			$phpexcel->getActiveSheet()->setCellValue('D1', "Width");
			$phpexcel->getActiveSheet()->setCellValue('E1', "Height");
			$phpexcel->getActiveSheet()->setCellValue('F1', "Quantity");
			$phpexcel->getActiveSheet()->setCellValue('G1', "Tracking");
			$phpexcel->getActiveSheet()->setCellValue('H1', "Tracking number");
			$phpexcel->getActiveSheet()->setCellValue('I1', "SKU");
			$phpexcel->getActiveSheet()->setCellValue('J1', "Declare Name");
			$phpexcel->getActiveSheet()->setCellValue('K1', "Declare Value");
			$phpexcel->getActiveSheet()->setCellValue('L1', "DeclareWeight");
			$phpexcel->getActiveSheet()->setCellValue('M1', "DeclareQuantity");
			$phpexcel->getActiveSheet()->setCellValue('N1', "Buyer");
			$phpexcel->getActiveSheet()->setCellValue('O1', "Address Line 1");
			$phpexcel->getActiveSheet()->setCellValue('P1', "Address Line 2");
			$phpexcel->getActiveSheet()->setCellValue('Q1', "City");
			$phpexcel->getActiveSheet()->setCellValue('R1', "Province");
			$phpexcel->getActiveSheet()->setCellValue('S1', "Postcode");
			$phpexcel->getActiveSheet()->setCellValue('T1', "Country");
			$phpexcel->getActiveSheet()->setCellValue('U1', "Phone Number");
			$phpexcel->getActiveSheet()->setCellValue('V1', "Email");
			$i = 2;
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'weight as declared_weight, declared_value, declared_name_en, number as sku', 'product_basic.id=sales_order_item.product_basic_id')
					->joinLeft('product_warehouse', '', 'product_warehouse.product_basic_id=product_basic.id and product_warehouse.warehouse_id='.$r['warehouse_id'])
					->joinLeft('product_material', 'specifications', 'product_warehouse.product_material_id=product_material.id')
					->asArray()->getAll();
				$specifications = explode('*', $item[0]['specifications']);
				$phpexcel->getActiveSheet()->setCellValue('A'.$i, '中英专线Packet2');
				$phpexcel->getActiveSheet()->setCellValue('B'.$i, $r['weight']);
				$phpexcel->getActiveSheet()->setCellValue('C'.$i, isset($specifications[0])?$specifications[0]*10:'');
				$phpexcel->getActiveSheet()->setCellValue('D'.$i, isset($specifications[1])?$specifications[1]*10:'');
				$phpexcel->getActiveSheet()->setCellValue('E'.$i, isset($specifications[2])?$specifications[2]*10:'');
				$phpexcel->getActiveSheet()->setCellValue('F'.$i, $r['product_quantity']);
				$phpexcel->getActiveSheet()->setCellValue('G'.$i, ($r['shipping_method'] == 'racl')?'是':'否');
				$phpexcel->getActiveSheet()->setCellValue('H'.$i, $r['tracking_number']);
				$phpexcel->getActiveSheet()->setCellValue('N'.$i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('O'.$i, $r['street1']);
				$phpexcel->getActiveSheet()->setCellValue('P'.$i, $r['street2']);
				$phpexcel->getActiveSheet()->setCellValue('Q'.$i, $r['city']);
				$phpexcel->getActiveSheet()->setCellValue('R'.$i, $r['state']);
				$phpexcel->getActiveSheet()->setCellValue('S'.$i, $r['zip']);
				$phpexcel->getActiveSheet()->setCellValue('T'.$i, $r['country']);
				$phpexcel->getActiveSheet()->setCellValue('U'.$i, $r['phone']);
				$phpexcel->getActiveSheet()->setCellValue('V'.$i, $r['email']);
				foreach ($item as $it)
				{
					$phpexcel->getActiveSheet()->getCell('I'.$i)->setValueExplicit($it['sku'], PHPExcel_Cell_DataType::TYPE_STRING);
					$phpexcel->getActiveSheet()->setCellValue('J'.$i, $it['declared_name_en']);
					$phpexcel->getActiveSheet()->setCellValue('K'.$i, $it['declared_value']);
					$phpexcel->getActiveSheet()->setCellValue('L'.$i, $it['declared_weight']);
					$phpexcel->getActiveSheet()->setCellValue('M'.$i, $it['quantity']);
					$i++;
				}
			}
			$outputFileName = "SYOrderInfo.xls";
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			header('Content-Type: application/vnd.ms-excel; charset=utf-8');
			header("Content-Type: application/octet-stream");
			header("Content-Type: application/download");
			header('Content-Disposition:inline;filename="'.$outputFileName.'"');
			header("Content-Transfer-Encoding: binary");
			header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}
	
	function actionExportMCOrderInfo()
	{
		$this->_view['title'] = '导出米巢模板';
		$url_arr = json_decode($_REQUEST['url_arr_json'], true);
		if ( ! empty($url_arr))
		{
			$where = Sales_Order::buildSearchWhere($url_arr);
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->joinLeft('country', '', 'country.en_name=sales_order_customer_info.country')
				->setColumns('sales_order.number, country.code as country_code, sales_order.shipping_method, sales_order.weight, sales_order.product_quantity, sales_order.tracking_number, sales_order_customer_info.*')
				->asArray()->getAll();
			include Q::ini('custom_system/lib_dir').'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle("米巢订单模板表");
			$phpexcel->getProperties()->setSubject("米巢订单模板表");
			$phpexcel->getProperties()->setDescription("米巢订单模板表-运营支撑系统");
			$phpexcel->getProperties()->setKeywords("米巢订单模板");
			$phpexcel->getProperties()->setCategory("米巢订单模板");
			$phpexcel->setActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle("米巢订单模板");
			$phpexcel->getActiveSheet()->setCellValue('A1', "参考号");
			$phpexcel->getActiveSheet()->setCellValue('B1', "挂号条码");
			$phpexcel->getActiveSheet()->setCellValue('C1', "收件人姓名");
			$phpexcel->getActiveSheet()->setCellValue('D1', "收件人地址");
			$phpexcel->getActiveSheet()->setCellValue('E1', "收件人电话");
			$phpexcel->getActiveSheet()->setCellValue('F1', "收件人国家（2字编码）");
			$phpexcel->getActiveSheet()->setCellValue('G1', "邮编");
			$phpexcel->getActiveSheet()->setCellValue('H1', "件数");
			$phpexcel->getActiveSheet()->setCellValue('I1', "重量（kg）");
			$phpexcel->getActiveSheet()->setCellValue('J1', "海关品名");
			$phpexcel->getActiveSheet()->setCellValue('K1', "物品数量");
			$phpexcel->getActiveSheet()->setCellValue('L1', "申报价值");
			$phpexcel->getActiveSheet()->setCellValue('M1', "申报单价币种");
			$phpexcel->getActiveSheet()->setCellValue('N1', "备注");
			$phpexcel->getActiveSheet()->setCellValue('O1', "运输渠道");
			$i = 2;
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'declared_value, declared_name_en', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$declared_value = 0;
				foreach ($item as $it)
				{
					$declared_value += $it['declared_value'];
				}
				$phpexcel->getActiveSheet()->getCell('A'.$i)->setValueExplicit($r['number'], PHPExcel_Cell_DataType::TYPE_STRING);
				$phpexcel->getActiveSheet()->setCellValue('B'.$i, $r['tracking_number']);
				$phpexcel->getActiveSheet()->setCellValue('C'.$i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('D'.$i, $r['street1'].' '.$r['street2']);
				$phpexcel->getActiveSheet()->setCellValue('E'.$i, empty($r['phone'])? '0':$r['phone']);
				$phpexcel->getActiveSheet()->setCellValue('F'.$i, $r['country_code']);
				$phpexcel->getActiveSheet()->setCellValue('G'.$i, $r['zip']);
				$phpexcel->getActiveSheet()->setCellValue('H'.$i, 1);
				$phpexcel->getActiveSheet()->setCellValue('I'.$i, $r['weight']/1000);
				$phpexcel->getActiveSheet()->setCellValue('J'.$i, $item[0]['declared_name_en']);
				$phpexcel->getActiveSheet()->setCellValue('K'.$i, $r['product_quantity']);
				$phpexcel->getActiveSheet()->setCellValue('L'.$i, $declared_value);
				$phpexcel->getActiveSheet()->setCellValue('M'.$i, 'USD');
				$phpexcel->getActiveSheet()->setCellValue('N'.$i, '');
				$phpexcel->getActiveSheet()->setCellValue('O'.$i, '瑞典邮政小包');
				$i++;
			}
			$outputFileName = "MC.xls";
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			header("Content-Type: application/vnd.ms-execl");
			header("Content-Type: application/octet-stream");
			header("Content-Type: application/download");
			header('Content-Disposition:inline;filename="'.$outputFileName.'"');
			header("Content-Transfer-Encoding: binary");
			header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}
	
	function actionExportBYOrderInfo()
	{
		$this->_view['title'] = '导出贝易订单模板';
		if (isset($_REQUEST['ids']) || isset($_REQUEST['url_arr_json']))
		{
			$where = isset($_REQUEST['url_arr_json']) ? Sales_Order::buildSearchWhere(json_decode($_REQUEST['url_arr_json'], true)) : 'sales_order.id in (' . $_REQUEST['ids'] . ')';
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->setColumns('sales_order.number, sales_order.weight, sales_order.tracking_number, sales_order_customer_info.*')
				->asArray()->getAll();
			$check_declared_value = array();
			foreach ($result as $rr)
			{
				$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $rr['sales_order_id'])
					->joinLeft('product_basic', 'declared_value, declared_name_en', 'sales_order_item.product_basic_id=product_basic.id')
					->asArray()->getAll();
				if (array_key_exists($rr['fullname'], $check_declared_value))
				{
					$check_declared_value[$rr['fullname']]['rebuy_count']++;
				}
				else
				{
					$check_declared_value[$rr['fullname']]['count_declared_value'] = 0;
					$check_declared_value[$rr['fullname']]['rebuy_count'] = 1;
				}
				foreach ($item as $it)
				{
					$check_declared_value[$rr['fullname']]['count_declared_value'] += $it['declared_value'] * $it['quantity'];
				}
			}
			include Q::ini('custom_system/lib_dir').'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle('贝易订单信息表');
			$phpexcel->getProperties()->setSubject('贝易订单信息表');
			$phpexcel->getProperties()->setDescription('贝易订单信息表-运营系统支撑系统');
			$phpexcel->getProperties()->setKeywords('贝易订单信息表');
			$phpexcel->getProperties()->setCategory('贝易订单信息表');
			$phpexcel->setActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle('贝易订单信息表');
			$phpexcel->getActiveSheet()->setCellValue('A1', '');
			$phpexcel->getActiveSheet()->setCellValue('B1', 'HAWB');
			$phpexcel->getActiveSheet()->setCellValue('C1', 'Cnee’s name');
			$phpexcel->getActiveSheet()->setCellValue('D1', 'Recipient’s address 1');
			$phpexcel->getActiveSheet()->setCellValue('E1', 'Recipient’s address 2');
			$phpexcel->getActiveSheet()->setCellValue('F1', 'Recipient’s address 3');
			$phpexcel->getActiveSheet()->setCellValue('G1', 'Postcode');
			$phpexcel->getActiveSheet()->setCellValue('H1', 'COUNTRY');
			$phpexcel->getActiveSheet()->setCellValue('I1', 'Item description');
			$phpexcel->getActiveSheet()->setCellValue('J1', 'Commercial value in GBP');
			$phpexcel->getActiveSheet()->setCellValue('K1', 'weigh');
			$phpexcel->getActiveSheet()->setCellValue('L1', 'ebay ItemID');
			$phpexcel->getActiveSheet()->setCellValue('M1', '挂号条码');
			$i = 2;
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'number as product_number, declared_value, declared_name_en', 'sales_order_item.product_basic_id=product_basic.id')
					->asArray()->getAll();
				$phpexcel->getActiveSheet()->setCellValue('A'.$i, $i);
				$phpexcel->getActiveSheet()->setCellValue('B'.$i, $r['tracking_number'] ? $r['tracking_number'] : $r['number']);
				$phpexcel->getActiveSheet()->setCellValue('C'.$i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('D'.$i, $r['street1']);
				$phpexcel->getActiveSheet()->setCellValue('E'.$i, $r['city']);
				$phpexcel->getActiveSheet()->setCellValue('F'.$i, $r['state']);
				$phpexcel->getActiveSheet()->setCellValue('G'.$i, $r['zip']);
				$phpexcel->getActiveSheet()->setCellValue('H'.$i, $r['country']);
				$phpexcel->getActiveSheet()->setCellValue('I'.$i, isset($item[0]['declared_name_en']) ? $item[0]['declared_name_en'] : '');
				$phpexcel->getActiveSheet()->setCellValue('J'.$i, ($check_declared_value[$r['fullname']]['count_declared_value'] >= 15) ? sprintf('%.2f', (14.9 / $check_declared_value[$r['fullname']]['rebuy_count'])) : sprintf('%.2f', $check_declared_value[$r['fullname']]['count_declared_value'] / $check_declared_value[$r['fullname']]['rebuy_count']));
				$phpexcel->getActiveSheet()->setCellValue('K'.$i, $r['weight']);
				$phpexcel->getActiveSheet()->getCell('L'.$i)->setValueExplicit($item[0]['product_number'], PHPExcel_Cell_DataType::TYPE_STRING);
				$phpexcel->getActiveSheet()->setCellValue('M'.$i, '');
				$i++;
			}
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			$outputFileName="BY.xls";
			header("Content-Type: application/vnd.ms-excel");
			header("Content-type: application/octet-stream");
			header("Content-type: application/download");
			header('Content-Disposition:inline;filename="' . $outputFileName . '"');
			header("Content-Transfer-Encoding:binary");
			header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}
	
	function actionExportEUBOrderInfo()
	{
		$this->_view['title'] = '导出EUB订单模板';
		if (isset($_REQUEST['ids']))
		{
			$result = Sales_order::find('sales_order.id in(' . $_REQUEST['ids'] . ')')
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->setColumns('sales_order.id as sales_order_id, sales_order.handle_status, sales_order.number, sales_order.tracking_number, sales_order.product_quantity, sales_order.weight, sales_order_customer_info.*')
				->asArray()->getAll();
			include Q::ini('custom_system/lib_dir').'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle('EUB订单模板表');
			$phpexcel->getProperties()->setSubject('EUB订单模板表');
			$phpexcel->getProperties()->setDescription('EUB订单模板表-运营系统支撑系统');
			$phpexcel->getProperties()->setKeywords('EUB订单模板表');
			$phpexcel->getProperties()->setCategory('EUB订单模板表');
			$phpexcel->setActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle('EUB订单模板表');
			$styleThinBlackBorderOutline = array(
				'borders' => array (
            		'outline' => array (
            		 	'style' => PHPExcel_Style_Border::BORDER_THIN,
						'color' => array ('argb' => 'FF000000'),
           			),
				),
			);
			$phpexcel->getActiveSheet()->getStyle( 'A1:AV1')->applyFromArray($styleThinBlackBorderOutline);
			$phpexcel->getActiveSheet()->getStyle( 'A1:AV1')->getFont()->setBold(true);
			$phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth('20');
			$phpexcel->getActiveSheet()->getStyle('A1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('A1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('A1', '客户订单');
			$phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth('20');
			$phpexcel->getActiveSheet()->getStyle('B1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('B1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('B1', '运输方式');
			$phpexcel->getActiveSheet()->getColumnDimension('C')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('C1', '跟踪号');
			$phpexcel->getActiveSheet()->getColumnDimension('D')->setWidth('15');
			$phpexcel->getActiveSheet()->getStyle('D1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('D1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('D1', '收件人国家');
			$phpexcel->getActiveSheet()->getColumnDimension('E')->setWidth('20');
			$phpexcel->getActiveSheet()->getStyle('E1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('E1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('E1', '收件人姓');
			$phpexcel->getActiveSheet()->getColumnDimension('F')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('F1', '收件人名字');
			$phpexcel->getActiveSheet()->getColumnDimension('G')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('G1', '收件人公司');
			$phpexcel->getActiveSheet()->getColumnDimension('H')->setWidth('20');
			$phpexcel->getActiveSheet()->getStyle('H1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('H1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('H1', '收件人地址');
			$phpexcel->getActiveSheet()->getColumnDimension('I')->setWidth('20');
			$phpexcel->getActiveSheet()->getStyle('I1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('I1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('I1', '城市');
			$phpexcel->getActiveSheet()->getColumnDimension('J')->setWidth('12');
			$phpexcel->getActiveSheet()->setCellValue('J1', '省/州');
			$phpexcel->getActiveSheet()->getColumnDimension('K')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('K1', '邮编');
			$phpexcel->getActiveSheet()->getColumnDimension('L')->setWidth('20');
			$phpexcel->getActiveSheet()->getStyle('L1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('L1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('L1', '电话');
			$phpexcel->getActiveSheet()->getColumnDimension('M')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('M1', '收件人税号');
			$phpexcel->getActiveSheet()->getColumnDimension('N')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('N1', '发件人姓');
			$phpexcel->getActiveSheet()->getColumnDimension('O')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('O1', '发件人名字');
			$phpexcel->getActiveSheet()->getColumnDimension('P')->setWidth('40');
			$phpexcel->getActiveSheet()->setCellValue('P1', '发件人公司');
			$phpexcel->getActiveSheet()->getColumnDimension('Q')->setWidth('40');
			$phpexcel->getActiveSheet()->setCellValue('Q1', '发货地址');
			$phpexcel->getActiveSheet()->getColumnDimension('R')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('R1', '城市');
			$phpexcel->getActiveSheet()->getColumnDimension('S')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('S1', '省/州');
			$phpexcel->getActiveSheet()->getColumnDimension('T')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('T1', '发件人邮编');
			$phpexcel->getActiveSheet()->getColumnDimension('U')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('U1', '发件人电话');
			$phpexcel->getActiveSheet()->setCellValue('V1', '是否退回');
			$phpexcel->getActiveSheet()->setCellValue('W1', '保险类型');
			$phpexcel->getActiveSheet()->setCellValue('X1', '保险价值 ');
			$phpexcel->getActiveSheet()->setCellValue('Y1', '敏感货品');
			$phpexcel->getActiveSheet()->setCellValue('Z1', '申报类型');
			$phpexcel->getActiveSheet()->setCellValue('AA1', '件数');
			$phpexcel->getActiveSheet()->getColumnDimension('AB')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('AB1', '包裹单边长');
			$phpexcel->getActiveSheet()->getColumnDimension('AC')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('AC1', '包裹单边宽');
			$phpexcel->getActiveSheet()->getColumnDimension('AD')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('AD1', '包裹单边高');
			$phpexcel->getActiveSheet()->getStyle('AE1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('AE1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->getColumnDimension('AE')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('AE1', '包裹总重量');
			$phpexcel->getActiveSheet()->getColumnDimension('AF')->setWidth('25');
			$phpexcel->getActiveSheet()->setCellValue('AF1', '是否关税预付');
			$phpexcel->getActiveSheet()->getColumnDimension('AG')->setWidth('30');
			$phpexcel->getActiveSheet()->getStyle('AG1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('AG1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('AG1', '申报名称1');
			$phpexcel->getActiveSheet()->getColumnDimension('AH')->setWidth('30');
			$phpexcel->getActiveSheet()->getStyle('AH1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('AH1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('AH1', '申报中文名称1');
			$phpexcel->getActiveSheet()->setCellValue('AI1', '海关编码');
			$phpexcel->getActiveSheet()->getStyle('AJ1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('AJ1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('AJ1', '数量1');
			$phpexcel->getActiveSheet()->getStyle('AK1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('AK1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('AK1', '单价1(usd)');
			$phpexcel->getActiveSheet()->getColumnDimension('AL')->setWidth('15');
			$phpexcel->getActiveSheet()->getStyle('AL1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('AL1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('AL1', '净重量(kg)');
			$phpexcel->getActiveSheet()->getColumnDimension('AM')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('AM1', '销售链接1');
			$phpexcel->getActiveSheet()->getColumnDimension('AN')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('AN1', '备注');
			$phpexcel->getActiveSheet()->getColumnDimension('AO')->setWidth('30');
			$phpexcel->getActiveSheet()->setCellValue('AO1', '申报名称2');
			$phpexcel->getActiveSheet()->getColumnDimension('AP')->setWidth('30');
			$phpexcel->getActiveSheet()->setCellValue('AP1', '申报中文名2');
			$phpexcel->getActiveSheet()->setCellValue('AQ1', '海关编码');
			$phpexcel->getActiveSheet()->setCellValue('AR1', '数量2');
			$phpexcel->getActiveSheet()->setCellValue('AS1', '单价2(usd)');
			$phpexcel->getActiveSheet()->getColumnDimension('AT')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('AT1', '净重量2(kg)');
			$phpexcel->getActiveSheet()->getColumnDimension('AU')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('AU1', '销售链接2');
			$phpexcel->getActiveSheet()->getColumnDimension('AV')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('AV1', '备注2');
			$i = 2;
			foreach($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'number as product_number, weight, declared_value, declared_name_en, declared_name_cn', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$declared_value = 0;
				foreach ($item as $it)
				{
					$declared_value += $it['declared_value'];
				}
				$declared_value = ($declared_value > 20) ? 19.9 : $declared_value;
				$phpexcel->getActiveSheet()->setCellValue('A' . $i, $r['number']);
				$phpexcel->getActiveSheet()->setCellValue('B' . $i, 'EUB-FZ');
				$phpexcel->getActiveSheet()->setCellValue('C' . $i, $r['tracking_number']);
				$phpexcel->getActiveSheet()->setCellValue('D' . $i, $r['country_cn']);
				$phpexcel->getActiveSheet()->setCellValue('E' . $i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('F' . $i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('G' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('H' . $i, $r['street1'] . ' ' . $r['street2']);
				$phpexcel->getActiveSheet()->setCellValue('I' . $i, $r['city']);
				$phpexcel->getActiveSheet()->setCellValue('J' . $i, $r['state']);
				$phpexcel->getActiveSheet()->setCellValue('K' . $i, $r['zip']);
				$phpexcel->getActiveSheet()->setCellValue('L' . $i, $r['phone']);
				$phpexcel->getActiveSheet()->setCellValue('M' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('N' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('O' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('P' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('Q' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('R' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('S' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('T' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('U' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('V' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('W' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('X' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('Y' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('Z' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AA' . $i, $r['product_quantity']);
				$phpexcel->getActiveSheet()->setCellValue('AB' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AC' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AD' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AE' . $i, ($item[0]['weight']/1000 <= 2) ? ($item[0]['weight']/1000) * $r['product_quantity'] : 1.99 * $r['product_quantity']);
				$phpexcel->getActiveSheet()->setCellValue('AF' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AG' . $i, $item[0]['declared_name_en']);
				$phpexcel->getActiveSheet()->setCellValue('AH' . $i, $item[0]['declared_name_cn']);
				$phpexcel->getActiveSheet()->setCellValue('AI' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AJ' . $i, $r['product_quantity']);
				$phpexcel->getActiveSheet()->setCellValue('AK' . $i, $declared_value/$r['product_quantity']);
				$phpexcel->getActiveSheet()->setCellValue('AL' . $i, ($item[0]['weight']/1000 <= 2) ? $item[0]['weight']/1000 : 1.99);
				$phpexcel->getActiveSheet()->setCellValue('AM' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AN' . $i, $r['number']);
				$phpexcel->getActiveSheet()->setCellValue('AO' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AP' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AQ' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AR' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AS' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AT' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AU' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AV' . $i, '');
				$i++;
			}
			$outputFileName = 'EUB.xls';
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			header("Content-Type: application/vnd.ms-execl");
			header("Content-Type: application/octet-stream");
			header("Content-Type: application/download");
			header('Content-Disposition:inline;filename="'.$outputFileName.'"');
			header("Content-Transfer-Encoding: binary");
			header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}

	function actionExportMYOrderInfo()
	{
		$this->_view['title'] = '导出马邮订单模板';
		if (isset($_REQUEST['ids']))
		{
			$result = Sales_order::find('sales_order.id in(' . $_REQUEST['ids'] . ')')
					->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
					->setColumns('sales_order.weight, sales_order.tracking_number, sales_order_customer_info.*')
					->asArray()->getAll();
			include Q::ini('custom_system/lib_dir').'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle('马邮订单模板表');
			$phpexcel->getProperties()->setSubject('马邮订单模板表');
			$phpexcel->getProperties()->setDescription('马邮订单模板表-运营支撑系统');
			$phpexcel->getProperties()->setKeywords('马邮订单模板');
			$phpexcel->getProperties()->setCategory('马邮订单模板');
			$phpexcel->setActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle('马邮订单模板');
			$phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
			$phpexcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
			$phpexcel->getActiveSheet()->getColumnDimension('E')->setWidth(12);
			$phpexcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
			$phpexcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
			$phpexcel->getActiveSheet()->setCellValue('A1', '');
			$phpexcel->getActiveSheet()->setCellValue('B1', 'HAWB');
			$phpexcel->getActiveSheet()->setCellValue('C1', 'Cnee’s name');
			$phpexcel->getActiveSheet()->setCellValue('D1', 'Recipient’s address 1');
			$phpexcel->getActiveSheet()->setCellValue('E1', 'Recipient’s address 2');
			$phpexcel->getActiveSheet()->setCellValue('F1', 'Recipient’s address 3');
			$phpexcel->getActiveSheet()->setCellValue('G1', 'Postcode');
			$phpexcel->getActiveSheet()->setCellValue('H1', 'COUNTRY');
			$phpexcel->getActiveSheet()->setCellValue('I1', 'Item description');
			$phpexcel->getActiveSheet()->setCellValue('J1', 'Commercial value in GBP');
			$phpexcel->getActiveSheet()->setCellValue('K1', 'weigh(g)');
			$phpexcel->getActiveSheet()->setCellValue('L1', 'ebay ItemID');
			$i = 2;
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'declared_value, declared_name_en', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$declared_value = 0;
				foreach ($item as $it)
				{
					$declared_value += $it['declared_value'];
				}
				$phpexcel->getActiveSheet()->setCellValue('A' . $i, $i - 1);
				$phpexcel->getActiveSheet()->setCellValue('B'.$i, $r['tracking_number']);
				$phpexcel->getActiveSheet()->setCellValue('C'.$i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('D'.$i, $r['street1']);
				$phpexcel->getActiveSheet()->setCellValue('E'.$i, $r['street2']);
				$phpexcel->getActiveSheet()->setCellValue('F'.$i, '');
				$phpexcel->getActiveSheet()->setCellValue('G'.$i, $r['zip']);
				$phpexcel->getActiveSheet()->setCellValue('H'.$i, $r['country']);
				$phpexcel->getActiveSheet()->setCellValue('I'.$i, $item[0]['declared_name_en']);
				$phpexcel->getActiveSheet()->setCellValue('J'.$i, ($declared_value>=14.9) ? 14.9 : $declared_value);
				$phpexcel->getActiveSheet()->setCellValue('K'.$i, $r['weight']);
				$phpexcel->getActiveSheet()->setCellValue('L'.$i, '');
				$i++;
			}
			$outputFileName = "马邮订单模板.xls";
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			header("Content-Type: application/vnd.ms-execl");
			header("Content-Type: application/octet-stream");
			header("Content-Type: application/download");
			header('Content-Disposition:inline;filename="'.$outputFileName.'"');
			header("Content-Transfer-Encoding: binary");
			header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}
	
	function actionExportRHKPackageOrderInfo()
	{
		$this->_view['title'] = '导出HK小包挂订单模板';
		if (isset($_REQUEST['ids']) || isset($_REQUEST['url_arr_json']))
		{
			$where = isset($_REQUEST['url_arr_json']) ? Sales_Order::buildSearchWhere(json_decode($_REQUEST['url_arr_json'], true)) : 'sales_order.id in (' . $_REQUEST['ids'] . ')';
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->setColumns('sales_order.number, sales_order.tracking_number, sales_order.weight, sales_order_customer_info.*')
				->order('sales_order.sales_time asc')->asArray()->getAll();
			include Q::ini('custom_system/lib_dir') . 'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle('香港小包挂号订单模板表');
			$phpexcel->getProperties()->setSubject('香港小包挂号订单模板表');
			$phpexcel->getProperties()->setDescription('香港小包挂号订单模板表-运营系统支撑系统');
			$phpexcel->getProperties()->setKeywords('香港小包挂号订单模板表');
			$phpexcel->getProperties()->setCategory('香港小包挂号订单模板表');
			$phpexcel->getActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle('香港小包挂号订单模板');
			$phpexcel ->getActiveSheet()->getStyle("A1:K" . (count($result) + 1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$phpexcel->getActiveSheet()->getStyle('A1:K1')->getFont()->setBold(true);
			$phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('A1', '条码');
			$phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('B1', '收件人姓名');
			$phpexcel->getActiveSheet()->getColumnDimension('C')->setWidth('40');
			$phpexcel->getActiveSheet()->setCellValue('C1', '收件人地址');
			$phpexcel->getActiveSheet()->getColumnDimension('D')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('D1', '国家');
			$phpexcel->getActiveSheet()->getColumnDimension('E')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('E1', '重量（克）');
			$phpexcel->getActiveSheet()->getColumnDimension('F')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('F1', '国家（中文）');
			$phpexcel->getActiveSheet()->getColumnDimension('G')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('G1', '邮编');
			$phpexcel->getActiveSheet()->getColumnDimension('H')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('H1', '州');
			$phpexcel->getActiveSheet()->getColumnDimension('I')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('I1', '城市');
			$phpexcel->getActiveSheet()->getColumnDimension('J')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('J1', '电话');
			$phpexcel->getActiveSheet()->getColumnDimension('K')->setWidth('15');
			$phpexcel->getActiveSheet()->setCellValue('K1', '品名');
			$i = 2;
			foreach ($result as $r)
			{
				$sales_order_item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $r['id'])
					->joinLeft('product_basic', 'declared_name_en', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$phpexcel->getActiveSheet()->setCellValue('A' . $i, empty($r['tracking_number']) ? $r['number'] : $r['tracking_number']);
				$phpexcel->getActiveSheet()->setCellValue('B' . $i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('C' . $i, $r['street1'] . ' ' . $r['street2'] . ' ' . $r['city'] . ' ' . $r['state']);
				$phpexcel->getActiveSheet()->setCellvalue('D' . $i, $r['country']);
				$phpexcel->getActiveSheet()->setCellValue('E' . $i, $r['weight']);
				$phpexcel->getActiveSheet()->setCellValue('F' . $i, $r['country_cn']);
				$phpexcel->getActiveSheet()->getCell('G' . $i)->setValueExplicit($r['zip'], PHPExcel_Cell_DataType::TYPE_STRING);
				$phpexcel->getActiveSheet()->setCellValue('H' . $i, $r['state']);
				$phpexcel->getActiveSheet()->setCellValue('I' . $i, $r['city']);
				$phpexcel->getActiveSheet()->setCellValue('J' . $i, $r['phone']);
				$phpexcel->getActiveSheet()->setCellValue('K' . $i, $sales_order_item[0]['declared_name_en']);
				$i++;
			}
			$outputFileName = '香港小包挂号模板.xls';
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			header("Content-Type: application/vnd.ms-execl");
			header("Content-Type: application/octet-stream");
			header("Content-Type: application/download");
			header('Content-Disposition:inline;filename="'.$outputFileName.'"');
			header("Content-Transfer-Encoding: binary");
			header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}
	
	function actionExportBUBOrderInfo()
	{
		$this->_view['title'] = '导出贝邮宝订单模板';
		if (isset($_REQUEST['ids']) || isset($_REQUEST['url_arr_json']))
		{
			$where = isset($_REQUEST['url_arr_json']) ? Sales_Order::buildSearchWhere(json_decode($_REQUEST['url_arr_json'], true)) : 'sales_order.id in (' . $_REQUEST['ids'] . ')';
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->setColumns('sales_order.*, sales_order_customer_info.*')
				->order('sales_order.sales_time asc')->asArray()->getAll();
			include Q::ini('custom_system/lib_dir') . 'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle('贝邮宝订单模板表');
			$phpexcel->getProperties()->setSubject('贝邮宝订单模板表');
			$phpexcel->getProperties()->setDescription('贝邮宝订单模板表-运营系统支撑系统');
			$phpexcel->getProperties()->setKeywords('贝邮宝订单模板表');
			$phpexcel->getProperties()->setCategory('贝邮宝订单模板表');
			$phpexcel->getActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle('贝邮宝订单模板');
			$phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('A1', '英文寄件人姓名');
			$phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('B1', '寄件人地址');
			$phpexcel->getActiveSheet()->getColumnDimension('C')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('C1', '寄件人省名英文');
			$phpexcel->getActiveSheet()->getColumnDimension('D')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('D1', '寄件人城市名英文');
			$phpexcel->getActiveSheet()->getColumnDimension('E')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('E1', '寄件人电话');
			$phpexcel->getActiveSheet()->getColumnDimension('F')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('F1', '收件人姓名(到达国语言)');
			$phpexcel->getActiveSheet()->getColumnDimension('G')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('G1', '收件人姓名英文');
			$phpexcel->getActiveSheet()->getColumnDimension('H')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('H1', '收件人地址(到达国语言)');
			$phpexcel->getActiveSheet()->getColumnDimension('I')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('I1', '收件人地址英文');
			$phpexcel->getActiveSheet()->getColumnDimension('J')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('J1', '收件人国家(到达国语言)');
			$phpexcel->getActiveSheet()->getColumnDimension('K')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('K1', '收件人国家中文');
			$phpexcel->getActiveSheet()->getColumnDimension('L')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('L1', '收件人英文国家名');
			$phpexcel->getActiveSheet()->getColumnDimension('M')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('M1', '收件人州名(到达国语言)');
			$phpexcel->getActiveSheet()->getColumnDimension('N')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('N1', '收件人英文州名');
			$phpexcel->getActiveSheet()->getColumnDimension('O')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('O1', '收件人城市名(到达国语言)');
			$phpexcel->getActiveSheet()->getColumnDimension('P')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('P1', '收件人英文城市名');
			$phpexcel->getActiveSheet()->setCellValue('Q1', '收件人邮编');
			$phpexcel->getActiveSheet()->setCellValue('R1', '收件人电话');
			$phpexcel->getActiveSheet()->setCellValue('S1', '内件详细名称');
			$phpexcel->getActiveSheet()->setCellValue('T1', '内件类型代码');
			$phpexcel->getActiveSheet()->setCellValue('U1', '重量');
			$phpexcel->getActiveSheet()->setCellValue('V1', '数量');
			$phpexcel->getActiveSheet()->setCellValue('W1', '单件重量');
			$phpexcel->getActiveSheet()->setCellValue('X1', '单价 ');
			$phpexcel->getActiveSheet()->setCellValue('Y1', '货物原产国');
			$phpexcel->getActiveSheet()->setCellValue('Z1', '交易金额');
			$phpexcel->getActiveSheet()->setCellValue('AA1', '交易号');
			$phpexcel->getActiveSheet()->setCellValue('AB1', '商户自定义');
			$phpexcel->getActiveSheet()->setCellValue('AC1', '是否挂号');
			for ($i=2; $i<=7; $i++)
			{
				$phpexcel->getActiveSheet()->setCellvalue('A' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('B' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('C' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('D' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('E' . $i, '12345678');
				$phpexcel->getActiveSheet()->setCellvalue('F' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('G' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('H' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('I' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('J' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('K' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('L' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('M' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('N' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('O' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('P' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('Q' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('R' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('S' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('T' . $i, '1');
				$phpexcel->getActiveSheet()->setCellvalue('U' . $i, '1');
				$phpexcel->getActiveSheet()->setCellvalue('V' . $i, '1');
				$phpexcel->getActiveSheet()->setCellvalue('W' . $i, '1');
				$phpexcel->getActiveSheet()->setCellvalue('X' . $i, '1');
				$phpexcel->getActiveSheet()->setCellvalue('Y' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('Z' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('AA' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('AB' . $i, '运单数据样式，请不要删除');
				$phpexcel->getActiveSheet()->setCellvalue('AC' . $i, '0');
			}
			$i = 8;
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'weight, declared_value, declared_name_cn, declared_name_en', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$declared_value = 0;
				foreach ($item as $it)
				{
					$declared_value += $it['declared_value'];
				}
				$declared_value = ($declared_value > 20) ? 19.9 : $declared_value;
				$phpexcel->getActiveSheet()->setCellValue('A' . $i, 'jewel');
				$phpexcel->getActiveSheet()->setCellValue('B' . $i, '高唐新建区高普路广州互联网产业园1楼C101');
				$phpexcel->getActiveSheet()->setCellValue('C' . $i, 'GuangDong');
				$phpexcel->getActiveSheet()->setCellvalue('D' . $i, 'GuangZhou');
				$phpexcel->getActiveSheet()->setCellValue('E' . $i, '18148947176');
				$phpexcel->getActiveSheet()->setCellValue('F' . $i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('G' . $i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('H' . $i, $r['street1'] . ' ' . $r['street2']);
				$phpexcel->getActiveSheet()->setCellValue('I' . $i, $r['street1'] . ' ' . $r['street2']);
				$phpexcel->getActiveSheet()->setCellValue('J' . $i, $r['country']);
				$phpexcel->getActiveSheet()->setCellValue('K' . $i, $r['country_cn']);
				$phpexcel->getActiveSheet()->setCellValue('L' . $i, $r['country']);
				$phpexcel->getActiveSheet()->setCellValue('M' . $i, $r['state']);
				$phpexcel->getActiveSheet()->setCellValue('N' . $i, $r['state']);
				$phpexcel->getActiveSheet()->setCellValue('O' . $i, $r['city']);
				$phpexcel->getActiveSheet()->setCellValue('P' . $i, $r['city']);
				$phpexcel->getActiveSheet()->setCellValue('Q' . $i, $r['zip']);
				$phpexcel->getActiveSheet()->setCellValue('R' . $i, ($r['phone']) ? $r['phone'] : 'NULL');
				$phpexcel->getActiveSheet()->setCellValue('S' . $i, $item[0]['declared_name_cn']);
				$phpexcel->getActiveSheet()->setCellValue('T' . $i, 4);
				$phpexcel->getActiveSheet()->setCellValue('U' . $i, ($r['weight']/1000 <= 2) ? $r['weight']/1000 : 1.99);
				$phpexcel->getActiveSheet()->setCellValue('V' . $i, $r['product_quantity']);
				$phpexcel->getActiveSheet()->setCellValue('W' . $i, ($item[0]['weight']/1000 <= 2) ? $item[0]['weight']/1000 : 1.99);
				$phpexcel->getActiveSheet()->setCellValue('X' . $i, $declared_value/$r['product_quantity']);
				$phpexcel->getActiveSheet()->setCellValue('Y' . $i, 'China');
				$phpexcel->getActiveSheet()->setCellValue('Z' . $i, $r['amount']);
				$phpexcel->getActiveSheet()->setCellValue('AA' . $i, $r['transaction_id']);
				$phpexcel->getActiveSheet()->setCellValue('AB' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('AC' . $i, '0');
				$i++;
			}
			$outputFileName = '贝邮宝模板.xls';
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			header("Content-Type: application/vnd.ms-execl");
			header("Content-Type: application/octet-stream");
			header("Content-Type: application/download");
			header('Content-Disposition:inline;filename="'.$outputFileName.'"');
			header("Content-Transfer-Encoding: binary");
			header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}
	
	function actionExportGLSOrderInfo()
	{
		$this->_view['title'] = '导出GLS订单模板';
		set_time_limit(0);
		if (isset($_REQUEST['ids']) || isset($_REQUEST['url_arr_json']))
		{
			$where = isset($_REQUEST['url_arr_json']) ? Sales_Order::buildSearchWhere(json_decode($_REQUEST['url_arr_json'], true)) : 'sales_order.id in (' . $_REQUEST['ids'] . ')';
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->joinLeft('country', '', 'country.en_name=sales_order_customer_info.country')
				->joinLeft('currency', '', 'currency.id=sales_order.currency_id')
				->setColumns('sales_order.number, sales_order.shipping_fee, sales_order.amount, sales_order.product_quantity, sales_order_customer_info.*, country.code as country_code, currency.code as currency_code')
				->asArray()->getAll();
			include Q::ini('custom_system/lib_dir') . 'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle('GLS模板');
			$phpexcel->getProperties()->setSubject('GLS模板');
			$phpexcel->getProperties()->setDescription('GLS模板-运营系统支撑系统');
			$phpexcel->getProperties()->setKeywords('GLS模板');
			$phpexcel->getProperties()->setCategory('GLS模板');
			$phpexcel->getActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle('导出GLS模板');
			$phpexcel->getActiveSheet()->setCellValue('A1', '交易单号');
			$phpexcel->getActiveSheet()->setCellValue('B1', '收货人ID');
			$phpexcel->getActiveSheet()->setCellValue('C1', '收货人姓名');
			$phpexcel->getActiveSheet()->setCellValue('D1', '收货人电话');
			$phpexcel->getActiveSheet()->setCellValue('E1', '收货人邮箱');
			$phpexcel->getActiveSheet()->setCellValue('F1', '收货人地址1');
			$phpexcel->getActiveSheet()->setCellValue('G1', '收货人地址2');
			$phpexcel->getActiveSheet()->setCellValue('H1', '收货人城市');
			$phpexcel->getActiveSheet()->setCellValue('I1', '收货人地区');
			$phpexcel->getActiveSheet()->setCellValue('J1', '收货人邮编');
			$phpexcel->getActiveSheet()->setCellValue('K1', '收货人国家');
			$phpexcel->getActiveSheet()->setCellValue('L1', 'SKU');
			$phpexcel->getActiveSheet()->setCellValue('M1', '商品名称');
			$phpexcel->getActiveSheet()->setCellValue('N1', '数量');
			$phpexcel->getActiveSheet()->setCellValue('O1', '卖出金额');
			$phpexcel->getActiveSheet()->setCellValue('P1', '运费');
			$phpexcel->getActiveSheet()->setCellValue('Q1', '交易编号');
			$phpexcel->getActiveSheet()->setCellValue('R1', '平台');
			$phpexcel->getActiveSheet()->setCellValue('S1', '付款日期');
			$phpexcel->getActiveSheet()->setCellValue('T1', 'HS Code');
			$phpexcel->getActiveSheet()->setCellValue('U1', '网站运输方式');
			$i = 2;
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'number as product_number, declared_value, declared_name_en, declared_name_cn', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$declared_value = 0;
				foreach ($item as $it)
				{
					$declared_value += $it['declared_value'];
				}
				$phpexcel->getActiveSheet()->setCellValue('A' . $i, $r['number']);
				$phpexcel->getActiveSheet()->setCellValue('B' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('C' . $i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('D' . $i, $r['phone']);
				$phpexcel->getActiveSheet()->setCellValue('E' . $i, $r['email']);
				$phpexcel->getActiveSheet()->setCellValue('F' . $i, $r['street1']);
				$phpexcel->getActiveSheet()->setCellValue('G' . $i, $r['street2']);
				$phpexcel->getActiveSheet()->setCellValue('H' . $i, $r['city']);
				$phpexcel->getActiveSheet()->setCellValue('I' . $i, $r['state']);
				$phpexcel->getActiveSheet()->getCell('J' . $i)->setValueExplicit($r['zip'], PHPExcel_Cell_DataType::TYPE_STRING);
				$phpexcel->getActiveSheet()->setCellValue('K' . $i, $r['country_code']);
				$phpexcel->getActiveSheet()->setCellValue('L' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('M' . $i, $item[0]['declared_name_cn']);
				$phpexcel->getActiveSheet()->setCellValue('N' . $i, $r['product_quantity']);
				$phpexcel->getActiveSheet()->setCellValue('O' . $i, $r['currency_code'] . $r['amount']);
				$phpexcel->getActiveSheet()->setCellValue('P' . $i, $r['currency_code'] . $r['shipping_fee']);
				$phpexcel->getActiveSheet()->setCellValue('Q' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('R' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('S' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('T' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('U' . $i, '');
				$i++;
			}
			$outputFileName = 'GLS模板.xls';
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			header("Content-Type: application/vnd.ms-excel");
			header("Content-Type: application/octet-stream");
			header("Content-Type: applicaiton/download");
			header('Content-Disposition:inine;filename="' . $outputFileName . '"');
			header("Content-Transfer-Encoding: binary");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}
	
	function actionExportDHLOrderInfo()
	{
		$this->_view['title'] = '导出DHL订单模板';
		if (isset($_REQUEST['ids']) || isset($_REQUEST['url_arr_json']))
		{
			$where = isset($_REQUEST['url_arr_json']) ? Sales_Order::buildSearchWhere(json_decode($_REQUEST['url_arr_json'], true)) : 'sales_order.id in (' . $_REQUEST['ids'] . ')';
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->setColumns('sales_order.*, sales_order_customer_info.sales_order_id, sales_order_customer_info.shop_buyer_id, sales_order_customer_info.fullname, sales_order_customer_info.phone, sales_order_customer_info.email, sales_order_customer_info.street1, sales_order_customer_info.street2, sales_order_customer_info.city, sales_order_customer_info.state, sales_order_customer_info.zip, sales_order_customer_info.country, sales_order_customer_info.country_cn, sales_order_customer_info.address_notes')
				->asArray()->getAll();
			include Q::ini('custom_system/lib_dir').'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle('DHL模板');
			$phpexcel->getProperties()->setSubject('DHL模板');
			$phpexcel->getProperties()->setDescription('DHL模板-运营系统支撑系统');
			$phpexcel->getProperties()->setKeywords('DHL模板');
			$phpexcel->getProperties()->setCategory('DHL模板');
			$phpexcel->getActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle('导出DHL模板');
			$phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth('10');
			$phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth('20');
			$phpexcel->getActiveSheet()->getColumnDimension('C')->setWidth('15');
			$phpexcel->getActiveSheet()->getColumnDimension('D')->setWidth('20');
			$phpexcel->getActiveSheet()->getColumnDimension('E')->setWidth('15');
			$phpexcel->getActiveSheet()->getColumnDimension('F')->setWidth('20');
			$phpexcel->getActiveSheet()->getColumnDimension('G')->setWidth('12');
			$phpexcel->getActiveSheet()->getColumnDimension('H')->setWidth('15');
			$phpexcel->getActiveSheet()->getColumnDimension('I')->setWidth('20');
			$phpexcel->getActiveSheet()->getColumnDimension('J')->setWidth('20');
			$phpexcel->getActiveSheet()->getColumnDimension('K')->setWidth('20');
			$phpexcel->getActiveSheet()->getColumnDimension('L')->setWidth('20');
			$phpexcel->getActiveSheet()->getColumnDimension('M')->setWidth('20');
			$phpexcel->getActiveSheet()->getColumnDimension('N')->setWidth('15');
			$phpexcel->getActiveSheet()->getColumnDimension('O')->setWidth('20');
			$phpexcel->getActiveSheet()->getColumnDimension('P')->setWidth('20');
			$phpexcel->getActiveSheet()->getColumnDimension('Q')->setWidth('20');
			$phpexcel->getActiveSheet()->setCellValue('A1', '序号');
			$phpexcel->getActiveSheet()->getStyle('B1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('B1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('B1', '日期(必填)');
			$phpexcel->getActiveSheet()->getStyle('C1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('C1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('C1', '原单号(必填)');
			$phpexcel->getActiveSheet()->setCellValue('D1', 'DHL转单号(我们自己填)');
			$phpexcel->getActiveSheet()->getStyle('E1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('E1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('E1', '重量(克)(必填)');
			$phpexcel->getActiveSheet()->getStyle('F1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('F1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('F1', '品名英文(必填)');
			$phpexcel->getActiveSheet()->getStyle('G1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('G1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('G1', '数量(必填)');
			$phpexcel->getActiveSheet()->getStyle('H1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('H1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('H1', '申报价值(必填)');
			$phpexcel->getActiveSheet()->getStyle('I1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('I1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('I1', '目的地国家(必填)');
			$phpexcel->getActiveSheet()->getStyle('J1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('J1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('J1', '收件人公司');
			$phpexcel->getActiveSheet()->getStyle('K1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('K1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('K1', '收件人(必填)');
			$phpexcel->getActiveSheet()->getStyle('L1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('L1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('L1', '收件人地址(必填)');
			$phpexcel->getActiveSheet()->getStyle('M1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('M1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('M1', '城市(必填)');
			$phpexcel->getActiveSheet()->getStyle('N1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('N1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('N1', '州(必填)');
			$phpexcel->getActiveSheet()->getStyle('O1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('O1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('O1', '邮编(必填)');
			$phpexcel->getActiveSheet()->getStyle('P1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
			$phpexcel->getActiveSheet()->getStyle('P1')->getFill()->getStartColor()->setARGB('#FFFF00');
			$phpexcel->getActiveSheet()->setCellValue('P1', '收件人电话(必填)');
			$phpexcel->getActiveSheet()->setCellValue('Q1', 'remark');
			$i = 2;
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $r['id'])
					->joinLeft('product_basic', 'number as product_number, declared_value, declared_name_en, declared_name_cn', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$declared_value = 0;
				foreach ($item as $it)
				{
					$declared_value += $it['declared_value'];
				}
				$phpexcel->getActiveSheet()->setCellValue('A' . $i, $i-1);
				$phpexcel->getActiveSheet()->setCellValue('B' . $i, $r['shipped_time']);
				$phpexcel->getActiveSheet()->setCellValue('C' . $i, $r['number']);
				$phpexcel->getActiveSheet()->setCellValue('D' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('E' . $i, $r['weight']);
				$phpexcel->getActiveSheet()->setCellValue('F' . $i, $item[0]['declared_name_en']);
				$phpexcel->getActiveSheet()->setCellValue('G' . $i, $r['product_quantity']);
				$phpexcel->getActiveSheet()->setCellValue('H' . $i, $declared_value);
				$phpexcel->getActiveSheet()->setCellValue('I' . $i, $r['country']);
				$phpexcel->getActiveSheet()->setCellValue('J' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('K' . $i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('L' . $i, $r['street1'] . ' ' . $r['street2']);
				$phpexcel->getActiveSheet()->setCellValue('M' . $i, $r['city']);
				$phpexcel->getActiveSheet()->setCellValue('N' . $i, $r['state']);
				$phpexcel->getActiveSheet()->setCellValue('O' . $i, $r['zip']);
				$phpexcel->getActiveSheet()->setCellValue('P' . $i, $r['phone']);
				$phpexcel->getActiveSheet()->setCellValue('Q' . $i, $r['number']);
				$i++;
			}
			$outputFileName = 'DHL模板.xls';
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			header("Content-Type: application/vnd.ms-excel");
			header("Content-Type: application/octet-stream");
			header("Content-Type: applicaiton/download");
			header('Content-Disposition:inine;filename="' . $outputFileName . '"');
			header("Content-Transfer-Encoding: binary");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}
	
	function actionExportBPOrderInfo()
	{
		$this->_view['title'] = '导出比利时邮政清单';
		if (isset($_REQUEST['ids']))
		{
			$where = "sales_order.id in ({$_REQUEST['ids']})";
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->joinLeft('country', '', 'country.en_name=sales_order_customer_info.country')
				->setColumns('sales_order.number, sales_order.tracking_number, sales_order.handle_status, sales_order.product_quantity, sales_order.weight, sales_order_customer_info.*, country.code as country_code')
				->asArray()->getAll();
			include Q::ini('custom_system/lib_dir') . 'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle('比利时邮政清单');
			$phpexcel->getProperties()->setSubject('比利时邮政清单');
			$phpexcel->getProperties()->setDescription('比利时邮政清单-运营系统支撑系统');
			$phpexcel->getProperties()->setKeywords('比利时邮政清单');
			$phpexcel->getProperties()->setCategory('比利时邮政清单');
			$phpexcel->getActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle('导出比利时邮政清单');
			$phpexcel->getActiveSheet()->setCellValue('A1', 'Status');
			$phpexcel->getActiveSheet()->setCellValue('B1', 'SKU (Required)');
			$phpexcel->getActiveSheet()->setCellValue('C1', 'Chinese content description (Required)');
			$phpexcel->getActiveSheet()->setCellValue('D1', 'Order Number (Required)');
			$phpexcel->getActiveSheet()->setCellValue('E1', 'Product barcode (Required when T&T option is valid!)');
			$phpexcel->getActiveSheet()->setCellValue('F1', 'Recipient name  (Required)');
			$phpexcel->getActiveSheet()->setCellValue('G1', 'Recipient street  (Required)');
			$phpexcel->getActiveSheet()->setCellValue('H1', 'Recipient housenumber  (Required)');
			$phpexcel->getActiveSheet()->setCellValue('I1', 'Recipient busnumber  (Optional)');
			$phpexcel->getActiveSheet()->setCellValue('J1', 'Recipient zipcode (Required)');
			$phpexcel->getActiveSheet()->setCellValue('K1', 'Recipient city (Required)');
			$phpexcel->getActiveSheet()->setCellValue('L1', 'Recipient state (Optional)');
			$phpexcel->getActiveSheet()->setCellValue('M1', 'Recipient country  (Required)');
			$phpexcel->getActiveSheet()->setCellValue('N1', 'Item content  (Required)');
			$phpexcel->getActiveSheet()->setCellValue('O1', 'Item count  (Required)');
			$phpexcel->getActiveSheet()->setCellValue('P1', 'Value (Required)');
			$phpexcel->getActiveSheet()->setCellValue('Q1', 'Currency (Required)');
			$phpexcel->getActiveSheet()->setCellValue('R1', 'Weight (Required)');
			$i = 2;
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'number as product_number, declared_value, declared_name_en, declared_name_cn', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$declared_value = 0;
				foreach ($item as $it)
				{
					$declared_value += $it['declared_value'];
				}
				$phpexcel->getActiveSheet()->setCellValue('A' . $i, Helper_BSS_Normal::getIniOne('sales_order_handle_status', 'value', $r['handle_status'], 'name'));
				$phpexcel->getActiveSheet()->setCellValue('B' . $i, $item[0]['product_number']);
				$phpexcel->getActiveSheet()->getCell('B' . $i)->setValueExplicit($item[0]['product_number'], PHPExcel_Cell_DataType::TYPE_STRING);
				$phpexcel->getActiveSheet()->setCellValue('C' . $i, $item[0]['declared_name_cn']);
				$phpexcel->getActiveSheet()->setCellValue('D' . $i, $r['number']);
				$phpexcel->getActiveSheet()->setCellValue('E' . $i, $r['tracking_number']);
				$phpexcel->getActiveSheet()->setCellValue('F' . $i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('G' . $i, $r['street1'] . ' ' . $r['street2']);
				$phpexcel->getActiveSheet()->setCellValue('H' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('I' . $i, '');
				$phpexcel->getActiveSheet()->getCell('J' . $i)->setValueExplicit($r['zip'], PHPExcel_Cell_DataType::TYPE_STRING);
				$phpexcel->getActiveSheet()->setCellValue('K' . $i, $r['city']);
				$phpexcel->getActiveSheet()->setCellValue('L' . $i, $r['state']);
				$phpexcel->getActiveSheet()->setCellValue('M' . $i, $r['country_code']);
				$phpexcel->getActiveSheet()->setCellValue('N' . $i, $item[0]['declared_name_en']);
				$phpexcel->getActiveSheet()->setCellValue('O' . $i, $r['product_quantity']);
				$phpexcel->getActiveSheet()->setCellValue('P' . $i, $declared_value >= 21.99 ? 21.99 : $declared_value);
				$phpexcel->getActiveSheet()->setCellValue('Q' . $i, 'USD');
				$phpexcel->getActiveSheet()->setCellValue('R' . $i, $r['weight']);
				$i++;
			}
			$outputFileName = '比利时邮政清单.xls';
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			header("Content-Type: application/vnd.ms-excel");
			header("Content-Type: application/octet-stream");
			header("Content-Type: applicaiton/download");
			header('Content-Disposition:inine;filename="' . $outputFileName . '"');
			header("Content-Transfer-Encoding: binary");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}
	
	function actionExportDELineOrderInfo()
	{
		$this->_view['title'] = '导出中德平邮清单';
		if (isset($_REQUEST['ids']))
		{
			$where = "sales_order.id in ({$_REQUEST['ids']})";
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->joinLeft('country', '', 'country.en_name=sales_order_customer_info.country')
				->setColumns('sales_order.number, sales_order.tracking_number, sales_order.handle_status, sales_order.product_quantity, sales_order.weight, sales_order_customer_info.*, country.code as country_code')
				->asArray()->getAll();
			include Q::ini('custom_system/lib_dir') . 'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle('中德平邮清单');
			$phpexcel->getProperties()->setSubject('中德平邮清单');
			$phpexcel->getProperties()->setDescription('中德平邮清单-运营系统支撑系统');
			$phpexcel->getProperties()->setKeywords('中德平邮清单');
			$phpexcel->getProperties()->setCategory('中德平邮清单');
			$phpexcel->getActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle('中德平邮清单');
			$phpexcel->getActiveSheet()->setCellValue('A1', '发货方式代码');
			$phpexcel->getActiveSheet()->setCellValue('B1', '追踪号');
			$phpexcel->getActiveSheet()->setCellValue('C1', '收货人姓名必填');
			$phpexcel->getActiveSheet()->setCellValue('D1', '电话');
			$phpexcel->getActiveSheet()->setCellValue('E1', '邮箱');
			$phpexcel->getActiveSheet()->setCellValue('F1', '地址1');
			$phpexcel->getActiveSheet()->setCellValue('G1', '地址2');
			$phpexcel->getActiveSheet()->setCellValue('H1', '城市');
			$phpexcel->getActiveSheet()->setCellValue('I1', '州/省');
			$phpexcel->getActiveSheet()->setCellValue('J1', '邮编');
			$phpexcel->getActiveSheet()->setCellValue('K1', '国家');
			$phpexcel->getActiveSheet()->setCellValue('L1', '产品名');
			$phpexcel->getActiveSheet()->setCellValue('M1', 'SKU');
			$phpexcel->getActiveSheet()->setCellValue('N1', '数量');
			$phpexcel->getActiveSheet()->setCellValue('O1', '重量');
			$phpexcel->getActiveSheet()->setCellValue('P1', '申报价值');
			$i = 2;
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'number as product_number, declared_value, declared_name_en', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$declared_value = 0;
				foreach ($item as $it)
				{
					$declared_value += $it['declared_value'];
				}
				$phpexcel->getActiveSheet()->setCellValue('A' . $i, 'DEAM');
				$phpexcel->getActiveSheet()->setCellValue('B' . $i, $r['tracking_number']);
				$phpexcel->getActiveSheet()->setCellValue('C' . $i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('D' . $i, $r['phone']);
				$phpexcel->getActiveSheet()->setCellValue('E' . $i, $r['email']);
				$phpexcel->getActiveSheet()->setCellValue('F' . $i, $r['street1']);
				$phpexcel->getActiveSheet()->setCellValue('G' . $i, $r['street2']);
				$phpexcel->getActiveSheet()->setCellValue('H' . $i, $r['city']);
				$phpexcel->getActiveSheet()->setCellValue('I' . $i, $r['state']);
				$phpexcel->getActiveSheet()->getCell('J' . $i)->setValueExplicit($r['zip'], PHPExcel_Cell_DataType::TYPE_STRING);
				$phpexcel->getActiveSheet()->setCellValue('K' . $i, $r['country']);
				$phpexcel->getActiveSheet()->setCellValue('L' . $i, $item[0]['declared_name_en']);
				$phpexcel->getActiveSheet()->getCell('M' . $i)->setValueExplicit($item[0]['product_number'], PHPExcel_Cell_DataType::TYPE_STRING);
				$phpexcel->getActiveSheet()->setCellValue('N' . $i, $r['product_quantity']);
				$phpexcel->getActiveSheet()->setCellValue('O' . $i, $r['weight']);
				$phpexcel->getActiveSheet()->setCellValue('P' . $i, $declared_value >= 21.99 ? 21.99 : $declared_value);
				$i++;
			}
			$outputFileName = '中德平邮清单.xls';
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			header("Content-Type: application/vnd.ms-excel");
			header("Content-Type: application/octet-stream");
			header("Content-Type: applicaiton/download");
			header('Content-Disposition:inine;filename="' . $outputFileName . '"');
			header("Content-Transfer-Encoding: binary");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}
	
	function actionExportNLLineOrderInfo()
	{
		$this->_view['title'] = "导出荷兰专线预报表";
		if (isset($_REQUEST['url_arr_json']) || isset($_REQUEST['ids']))
		{
			$where = isset($_REQUEST['url_arr_json']) ? Sales_Order::buildSearchWhere(json_decode($_REQUEST['url_arr_json'], true)) : 'sales_order.id in (' . $_REQUEST['ids'] . ')';
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->joinLeft('currency', '', 'currency.id=sales_order.currency_id')
				->setColumns('sales_order.number, sales_order.shipping_method, currency.code as currency_code, sales_order_customer_info.*')
				->asArray()->getAll();
			$data = "版本7_1\t目的地国家(必填)\t货运方式(必填)\t收件人(必填)\t包裹详情_英文1\t包裹详情_中文1\t数量1\t币种1\t单价1\t包裹详情_英文2\t包裹详情_中文2\t数量2\t币种2\t单价2\t包裹详情_英文3\t包裹详情_中文3\t数量3\t币种3\t单价3\t包裹详情_英文4\t包裹详情_中文4\t数量4\t币种4\t单价4\t包裹详情_英文5\t包裹详情_中文5\t数量5\t币种5\t单价5\t收件人Email\t地址1(必填)\t地址2\t州(省)\t城市(必填)\t邮编(必填)\t电话\tpackinfo1\tpackinfo2\tpackinfo3\tUSPS3Days是否挂号\t客户订单编号\r\n";
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'declared_value, declared_name_cn, declared_name_en', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$code = array(26 => 'NLFC');
				if (array_key_exists($r['shipping_method'], $code))
				{
					$shipping_method = $code[$r['shipping_method']];
					$quantity = 0;
					if ($item)
					{
						foreach ($item as $it)
						{
							$quantity += $it['quantity'];
						}
						foreach ($r as $k => $v)
						{
							$r[$k] = str_replace('"', '""', $v);
						}
						$phone = ($r['phone'] === '') ? 0 : $r['phone'];
						$data .= "\t" . trim($r['country']) . "\t{$shipping_method}" . "\t" . trim($r['fullname']) . "\t{$item[0]['declared_name_en']}\t{$item[0]['declared_name_cn']}\t{$quantity}\t{$r['currency_code']}\t{$item[0]['declared_value']}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$r['email']}\t{$r['street1']}\t{$r['street2']}\t{$r['state']}\t{$r['city']}\t^{$r['zip']}\t^{$phone}\t{$r['number']}\t\t\t\t\t{$r['number']}\r\n";
					}
				}
				else
				{
					$data .= "\r\n勾选项单号为:" . $r['number'] . "的邮寄方式不是荷兰专线\r\n";
				}
			}
			$data = iconv("UTF-8","UTF-16LE",$data);
			$data = "\xFF\xFE".$data;
			header("Content-type: text;");
			header("Content-Disposition: attachment; filename=荷兰专线预报表" . date("YmdHis") . ".txt");
			header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
			header('Expires: 0');
			header('Pragma: public');
			echo $data;
			exit;
		}
	}
	
	function actionExportSZOrderInfo()
	{
		$this->_view['title'] = '导出苏州小包模板';
		if (isset($_REQUEST['url_arr_json']) || isset($_REQUEST['ids']))
		{
			$where = isset($_REQUEST['url_arr_json']) ? Sales_Order::buildSearchWhere(json_decode($_REQUEST['url_arr_json'], true)) : 'sales_order.id in (' . $_REQUEST['ids'] . ')';
			$result = Sales_Order::find($where)
				->joinLeft('sales_order_customer_info', '', 'sales_order_customer_info.sales_order_id=sales_order.id')
				->setColumns('sales_order.number, sales_order.tracking_number, sales_order.product_quantity, sales_order.weight, sales_order_customer_info.*')
				->asArray()->getAll();
			include Q::ini('custom_system/lib_dir') . 'PHPExcel.php';
			$phpexcel = new PHPExcel();
			$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
			$phpexcel->getProperties()->setTitle('苏州小包模板');
			$phpexcel->getProperties()->setSubject('苏州小包模板');
			$phpexcel->getProperties()->setDescription('苏州小包模板-运营系统支撑系统');
			$phpexcel->getProperties()->setKeywords('苏州小包模板');
			$phpexcel->getProperties()->setCategory('苏州小包模板');
			$phpexcel->getActiveSheetIndex(0);
			$phpexcel->getActiveSheet()->setTitle('苏州小包模板');
			$phpexcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(20);
			$phpexcel->getActiveSheet()->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
			$phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
			$phpexcel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
			$phpexcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
			$phpexcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
			$phpexcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
			$phpexcel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
			$phpexcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
			$phpexcel->getActiveSheet()->getColumnDimension('I')->setWidth(25);
			$phpexcel->getActiveSheet()->getColumnDimension('J')->setWidth(25);
			$phpexcel->getActiveSheet()->getColumnDimension('K')->setWidth(15);
			$phpexcel->getActiveSheet()->getColumnDimension('L')->setWidth(10);
			$phpexcel->getActiveSheet()->getColumnDimension('M')->setWidth(17);
			$phpexcel->getActiveSheet()->getColumnDimension('N')->setWidth(12);
			$phpexcel->getActiveSheet()->getColumnDimension('O')->setWidth(12);
			$phpexcel->getActiveSheet()->getColumnDimension('P')->setWidth(12);
			$phpexcel->getActiveSheet()->getStyle('A1:P1')->getFont()->setBold(true);
			$phpexcel->getActiveSheet()->getStyle('A1:P1')->getFont()->setSize(12);
			$phpexcel->getActiveSheet()->getStyle('A1:P1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$phpexcel->getActiveSheet()->setCellValue('A1', '客户单号');
			$phpexcel->getActiveSheet()->setCellValue('B1', '转单号');
			$phpexcel->getActiveSheet()->setCellValue('C1', '运输方式');
			$phpexcel->getActiveSheet()->setCellValue('D1', '目的国家');
			$phpexcel->getActiveSheet()->setCellValue('E1', '收件人姓名');
			$phpexcel->getActiveSheet()->setCellValue('F1', '州，省');
			$phpexcel->getActiveSheet()->setCellValue('G1', '城市');
			$phpexcel->getActiveSheet()->setCellValue('H1', '联系地址');
			$phpexcel->getActiveSheet()->setCellValue('I1', '收件人电话');
			$phpexcel->getActiveSheet()->setCellValue('J1', '收件人邮箱');
			$phpexcel->getActiveSheet()->setCellValue('K1', '收件人邮编');
			$phpexcel->getActiveSheet()->setCellValue('L1', '重量');
			$phpexcel->getActiveSheet()->setCellValue('M1', '海关报关品名1');
			$phpexcel->getActiveSheet()->setCellValue('N1', '配货信息1');
			$phpexcel->getActiveSheet()->setCellValue('O1', '申报价值1');
			$phpexcel->getActiveSheet()->setCellValue('P1', '申报数量1');
			$i = 2;
			foreach ($result as $r)
			{
				$item = Sales_Order_Item::find('sales_order_item.sales_order_id=?', $r['sales_order_id'])
					->joinLeft('product_basic', 'number as product_number, declared_value, declared_name_en, declared_name_cn', 'product_basic.id=sales_order_item.product_basic_id')
					->asArray()->getAll();
				$declared_value = 0;
				foreach ($item as $it)
				{
					$declared_value += $it['declared_value'];
				}
				$phpexcel->getActiveSheet()->setCellValue('A' . $i, $r['number']);
				$phpexcel->getActiveSheet()->setCellValue('B' . $i, $r['tracking_number']);
				$phpexcel->getActiveSheet()->setCellValue('C' . $i, '');
				$phpexcel->getActiveSheet()->setCellValue('D' . $i, $r['country']);
				$phpexcel->getActiveSheet()->setCellValue('E' . $i, $r['fullname']);
				$phpexcel->getActiveSheet()->setCellValue('F' . $i, $r['state']);
				$phpexcel->getActiveSheet()->setCellValue('G' . $i, $r['city']);
				$phpexcel->getActiveSheet()->setCellValue('H' . $i, $r['street1'] . ' ' . $r['street2']);
				$phpexcel->getActiveSheet()->setCellValue('I' . $i, $r['phone']);
				$phpexcel->getActiveSheet()->setCellValue('J' . $i, $r['email']);
				$phpexcel->getActiveSheet()->getCell('K' . $i)->setValueExplicit($r['zip'], PHPExcel_Cell_DataType::TYPE_STRING);
				$phpexcel->getActiveSheet()->setCellValue('L' . $i, $r['weight']);
				$phpexcel->getActiveSheet()->setCellValue('M' . $i, $item[0]['declared_name_en']);
				$phpexcel->getActiveSheet()->setCellValue('N' . $i, $item[0]['declared_name_cn']);
				$phpexcel->getActiveSheet()->setCellValue('O' . $i, $declared_value);
				$phpexcel->getActiveSheet()->setCellValue('P' . $i, $r['product_quantity']);
				$i++;
			}
			$outputFileName = '苏州小包清单.xls';
			$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
			header("Content-Type: application/vnd.ms-excel");
			header("Content-Type: application/octet-stream");
			header("Content-Type: applicaiton/download");
			header('Content-Disposition:inine;filename="' . $outputFileName . '"');
			header("Content-Transfer-Encoding: binary");
			header("Pragma: no-cache");
			$objWriter->save('php://output');
			exit;
		}
	}
	
	function actionTrackingNumberToSY()
	{
		$this->_view['title'] = '自动分配中邮追踪号';
		if ($this->_context->isGET())
		{
			$url_arr = Helper_BSS_Normal::buildCondition();
			$url_arr['trash_status'] = Q::ini('custom_flag/sales_order_trash_status/normal/value');
			$url_arr['order_operate_status'] = true;
			$url_arr['warehouse_id'] = Warehouse::getDefaultWarehouseId();
			$url_arr['shipping_method'][Shipping_Method::getShippingMethodByCode('GZ_R_CN_Package')] = Shipping_Method::getShippingMethodByCode('GZ_R_CN_Package');
			$url_arr['is_tracking_number'][1] = true;
			$where = Sales_Order::buildSearchWhere($url_arr);
			$sales_order = Sales_Order::find($where)->asArray()->getAll();
			$tracking_number = QDB::getConn()->execute('select value from sy_tracking_number where status=0 limit 0,' . count($sales_order))->fetchCol();
			foreach ($sales_order as $k => $so)
			{
				if (isset($tracking_number[$k]))
				{
					QDB::getConn()->execute('update sales_order set tracking_number=\'' . $tracking_number[$k] . '\' where id=' . $so['id']);
					QDB::getConn()->execute('update sy_tracking_number set status=1, time=\'' . CURRENT_DATETIME . '\', sales_order_id=' . $so['id'] . ' where value=\'' . $tracking_number[$k] . '\'');
				}
				else
				{
					return $this->_redirectMessage('分配部分失败', '追踪号已分配完！', $_SERVER['HTTP_REFERER'], FAILURE);
				}
			}
			return $this->_redirectMessage('分配成功！', '', $_SERVER['HTTP_REFERER'], SUCCESS);
		}
		else
		{
			return $this->_redirectMessage('提交方式有误！', '', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
}